How To with C#

Code examples on 'How To' create programs using C# (C Sharp)

This post describes how to make a simple text reader using C# in the .net environment.  The text reader will be programmed as a windows form.

In you form, start our by placing a label at the top, followed by a list box below it, followed by a second label below the list box.  Name the list box, lstData and the bottom most label, lblMsg.  Alternatively, you can download the zip file and run the code in your visual studio IDE instead.  Be sure you have visual studio express 2008 or later, although the project should open in vs2005.

 How much do I need to invest today in order to have $1,000,000 in the future?  To answer this question, you also need to know how long you are willing to leave your money invested and what the interest rate you will be paid.

Take the following equation that computes simple interest for you:

A = P(1 + i) ^ n

Under this scenario, you have a group of checkboxes where you need the values of those checkboxes to be displayed upon being checked.   The displayed values need to be updated upon checking and unchecking the check boxes. 

This example will illustrate how to write one event handler to multiple objects.  This example utilizes the checkbox objects.  In the app, the user has an option to check up to four checkboxes.  Each time he checks one, the total dollar value for each item the user is checking is displayed on a label. 

This program illustrates how to use random values.  This program also assigns values to a two dimensional array.  In the first dimension you will have the random variable and in the next it’s square.  Also, this program makes use of the string variable and adds values to the string variable every time during the loop.

Parallel arrays are two arrays that hold related values for a record in two separate arrays usign the element index to tie in the values.  For example, you can have an array of Wrestler and another array called Points.  The first array may be a string array with the values of

Using ArrayList we will create a program that will accept any number of grades, then except for the highest and lowest value, it will output what percent of 100 of each grade is.  This exercise probably does not have any practical use or value but it makes use of the following techniques:

As soon as you run this program you will see a prompt asking you to enter a value.  That is because random values from 1 - 20 were already assigned to the declared array.  Now, you are simply ready to ask the program if the value that you enter is present in the array or not.  In addition to telling you if it is there, it will also count the number of times a value appears if it appears. 

Do you want to learn how to create a program in C# that will generate pig Latin based on what you type?  Well it may be pretty useless but this program does allow you to see some concepts in action.

This program illustrates how to accept any number of names into an ArrayList.  It asks the user to enter the last name then first name of the person.  The input is controlled by a sentinel value where the user is asked to enter the word “END”.