1.

What are the main parts of a C# program?

Answer»

The MAIN parts of a C# program are given as follows:

  1. Namespace declaration
  2. Class
  3. Class methods
  4. Class attributes
  5. Main method
  6. Expressions and statements
  7. Comments

A BASIC program that DEMONSTRATES all these parts is given as follows:

using System; namespace Demo {   class Program   {      static void Main(string[] args)      {         // This program finds the sum of two NUMBERS         int a = 5, b = 9, c;         c = a + b;         Console.WriteLine("Sum of {0} and {1} is {2}", a, b, c);      }   } }

The output of the above program is given as follows:

Sum of 5 and 9 is 14

Now, the various parts of the program are explained as follows:

  1. The System namespace is included in the above program with the using keyword.
  2. Then a namespace Demo is declared.
  3. Next, the class Program is declared.
  4. After that the Main() method is provided. This method is the entry point of all the C# programs.
  5. In the Main() method, a comment is provided. This is ignored by the compiler.
  6. After that, there are various statements that find the sum of two numbers.
  7. Then the sum is printed using the Console.WriteLine().


Discussion

No Comment Found