Your First C# code

In this chapter you will learn:

How to write simple C# code?
Understand the C# programming structure?

Well, you have understand where to and how to execute your program. In this section you will see the detailed explanation of short C# program. It will help you to implement your logic into program. So, carefully study the code and get the basic C# programming structure.

Each program requires three important steps to do work. It is Input, Process and Output. It is the basic concept of almost all the programming language. It is also known as I-P-O cycle. The program requires some input from the user. Next, the program processes the input with programming language and finally shows the output.

  • Consider the simple C# code, in which you will enter your name and your name will be displayed with some text message in command prompt.

    Please Enter Your Good Name
    Steven Clark
    Welcome Steven Clark in your first csharp program

    However, classes and objects are not mentioned in initial level, so you can find Main(string[] agrs) method to writing code.


    It is used for including C# class library. C# has huge collection of classes and objects. If you want to use those classes then you will have to include their library name in your program.

    string name; //Variable for storing string value
    It is a string variable that stores value input by user. A variable is a symbolic name of special data types that is used to store value in memory temporarily. Here, name is variable of string data types.

    Console.WriteLine("Please Enter Your Good Name");
    It is used for displaying message on console.

    name = Console.ReadLine();
    Storing value in the name variable.

    Console.WriteLine("Welcome {0} in your first csharp program", name);
    Again used for displaying message on the console. A new thing in this line is {0}. It is pronounced as place holder that is used for displaying variable value. In the above line, {0} print the value of name.

    In C#, Console.WriteLine() and Console.ReadLine() are the very important method.
    Console.WriteLine() : It is used for displaying message on the console. Console.ReadLine() : It is used for accepting user input.


    In this chapter you learned about different section of C# code. You also learned how to write C# code. In next chapter, you will learn about various that are used in C#.

    2 thoughts on “Your First C# code”

    1. can i please get the info about the header file used in c# programs … if anyone ask about those header files purpose so we can answer without any hesitation…

    Leave a Reply

    Your email address will not be published. Required fields are marked *