back

0. Introduction and setup

This tutorial covers displaying a window, putting things like buttons and textboxes on the window, and then moving data to and from the window to a place to store the data, such as a SQL Server database or text files.

Examples

Simplest program to display a window (section 1):

img

Basic research and data entry tool (section 14):

img img

Basic program to open, edit, and save text (section 18):

img

Research tool that displays a table of records (section 22):

img

0.1 How to run C# program

To run a C# program, need to first create the C# program, then run it.

There are two steps to creating the C# program. First, we need to create a file that will store the written code for the program. Second, we need to translate that written code into code the computer can use to run. This is called "compiling" the program.

So, the three steps will be to create the C# file, compile the C# into an executable file, and then run the program.

0.1.1 Create C# file

Open a text file and save as with a “.cs” extension. Any name for the file prior to the ".cs" will work, in this example, the name "basic" is chosen, giving a file name of “basic.cs”.

The first example in the tutorial is:

img
[text]

Copy and paste this code into the “basic.cs” file.

0.1.2 Compile C# program

Open Windows command prompt by clicking the start menu and searching for “cmd” and then clicking on “cmd.exe”. Change directory into whatever folder you saved the .cs file by using “cd C:\folder”. For example, I saved the .cs file in the folder "", so used the command:

cd C:\

The program to compile C# programs is included with most or all Windows distributions. To set up the command prompt to use the C# compiler, need to add the location of the compiler to the "PATH" environment variable. This can be done permanently through the Control Panel, or temporarily, for as long as the command prompt is open, using the following command:

PATH C:\Windows\Microsoft.NET\Framework64\v3.5

Then, can compile the C# program into a file that can be run/executed using "csc programname.cs", where "programname" is the name of the .cs file:

csc basic.cs

This will create a file called "programname.exe" in the same folder the csc command was run from.

0.1.3 Run C# program

While still in the same folder as above, run the "programname.exe" file by just typing its name:

basic.exe