This tutorial will guide you how to create your first C# program, build and run it. If you are newbie to C# programming language, this tutorial is very important.
1.2 Let’s go
Creating first C# Program
Creating C# Program requires you to install .net framework. Currently the newest version of .net framework is 4.5. After you have installed .net framework, you must choose an editor to write C# program. The most famous editor is integrated in Microsoft Visual Studio. Others include Sharp Develop, CodeWright, Poorman IDE, EditPlus, JEdit
In this tutorial, I use Microsoft Visual Studio 2010 (.net framework 4.0) to create a C# program. Follow these steps as bellow:
In New Project windows, select type of language is C# and type of program is Console Application, then insert information of the program:
Click OK button to complete creating C# program. Visual Studio will create a solution with a program inside.
Edit the code in Program.cs file as bellow:
- #region "importing libraries area"
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- #region "program"
- namespace MyFirstProgram //this is namespace of our program
- class Program //this is name of our class
- static void Main(string args) //this is function' name. Main function is the starting point of the program
- //You can write you code here
- Console.WriteLine("This is my first C# program!");
Running the program
Click "Run" icon in menu bar or press F5 button to run the program. Bellow is the output of the program above:
In this lesson, we show you some points:
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.