Programming Tutorial in C# - Lab session 1

 

In this first session we're going to explore the Visual  Studio IDE and learn some fundamental  programming concepts.

 

Lab session 1) my first c# program.

 

Create a new console project in Visual Studio, inside the main function, see below, please type in the following;

 

   static void Main(string[] args)
        {

            Console.WriteLine("Please type in your name");

            string myVariable = Console.ReadLine();

            Console.WriteLine(string.Format("hello world from {0} at {1}", myVariable, DateTime.Now.ToString("g")));                               
               
        }

 

Notice the line,

 

string myVariable = Console.ReadLine();

 

The first part var myVariable, declares a string variable, a variable in programming is one of the most important concepts to learn, a variable allows the program to hold a value, in this case myVariable is assigned the value from the readline command.

 

The second part, adds the value contained in myVariable to place holder {0} and the current datatime to place holder {1}

 

 Console.WriteLine(string.Format("hello world from {0} at {1}", myVariable, DateTime.Now.ToString("g"))); 

 

We will diccuss where the program is stored (disk) where the variable values are held (RAM)  as an introduction to programming.

 

Well done this is your first program.

 

M
                             
            

 

 

I'm a paragraph. Click here to add your own text and edit me. I’m a great place for you to tell a story and let your users know a little more about you.

This is a great space to write long text about your company and your services. You can use this space to go into a little more detail about your company.

I'm a paragraph. Click here to add your own text and edit me. I’m a great place for you to tell a story and let your users know a little more about you.

This is a great space to write long text about your company and your services. You can use this space to go into a little more detail about your company.