28 Jan C# – Understanding First Program
In this lesson, we will write our first C# program. We will also understand what a C# program syntax looks like with its purpose. Before beginning with the example, let us see what a C# syntax includes:
- using System: We will write this as the first line of the program. This includes the System namespace using the using keyword in C#.
- Namespace: The namespace is basically a collection of classes. In our example, the namespace demo is having the class A namespace can have multiple classes.
- Class: Next, comes the class declaration. A class is a blueprint and consists of one or more methods. Our program is only having a single method Main().
- Main(): The first line in our class is the Main() since it is considered as the entry point of any C# program.
- WriteLine: Inside the Main() method, we have mentioned the Console class with a method WriteLine() to print a line. It will display the text inside it on the screen.
Let us see an example that we discussed above to understand to create and run our first C# Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
using System; namespace Demo { class Studyopedia { static void Main(string[] args) { Console.WriteLine("First csharp program..."); } } } |
Output
1 2 3 |
First csharp program... |
No Comments