C# is used to build various types of applications like:
Below is the simple C# code example to print a message:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FirstProgram
{
class Program
{
static void Main(string[] args) // Main Method
{
Console.WriteLine("This is C# Tutorial"); //Display message
Console.ReadKey();
}
}
}
Using is for including the System namespace, which is basically a collection of classes.
The class consists of methods of the program. The above code consists of the main method, which shows the behavior of the class.
Static is the keyword that is used to tell whether this method is accessible or not without instantiating the class.
Main() method is where the execution starts. Having only one main method in a program that specifies the behavior is mandatory. It is basically an invoked method to execute.
WriteLine() is used to get output. We can write System.Console.WriteLine(), where System is a namespace with class Console, and WriteLine are the methods to display any message of a class.
ReadKey() is held on the screen until a key is pressed.
When the above code is compiled and executed, it produces the following result:
It is good to have knowledge of the C language, which will help to understand the basic concepts and syntaxes.
This is for beginners so that they can understand the basics of C# programming and its applications and advantages.