C# Basic Syntax

This post is created to provide information regarding the basic syntax of a C# program. That is how a basic C# program can be written. So without any further delay, let's start the tutorial.

The very basic syntax of a C# program should be:

using System;
namespace MyNamespaceName
{
   class MyClassName
   {
      static void Main(string[] args)
      {
         // block of code
      }
   }
}

This is the syntax of a basic C# program. I already explained all the terms and statements written in the above basic syntax at the start of the C# tutorial. This is the link I have provided, which helps you go directly to the description section. But for now, let me create an example of the above basic syntax of a C# program.

using System;
namespace MyFirstCSharpProgram
{
    class MyClassXYZ
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello there,");
            Console.WriteLine("Is everything alright?");
        }
    }
}

since I am using "Microsoft Visual Studio" as my IDE to program with C#. Therefore, when I executed the above program in it, Here is the output that I got:

c sharp basic syntax example

I have highlighted the output text with a red half-circle so that you can focus on it directly. Sorry 🤥 that it does not look like a half-circle, but please focus on the output text only 😏.

C# Online Test


« Previous Tutorial Next Tutorial »