C# Basics-Sample C# code explanation (C#-4)

 


Let's get to know the sample code we used in previous examples.

Which was(C-1-1):

(C-1-1)

NOTE:

The code is numbered in the left corner of the image(C-1-1)

1st Line: Using System;

  • This line of code tells the computer to use some tools that will help write the program. which contains a variety of useful classes and methods for working with the .NET framework.


2nd Line: Blank Line

  • C# will ignore blank spaces. However, blank lines make the code more readable and clean.


3rd Line: namespace MyFirstProgram{}

  • This line of code gives a name to the collection of tools called MyFirstProgram which we will be using in the program. A namespace is used to organize code and prevent naming conflicts.

5th Line: class program{}

  • This line of code says that we are going to create a new thing (called a "class") and that we will call it a "program". A class is a blueprint for creating objects that can contain data and methods.

7th Line: static void Main (string[] args){}

  • This line of code says that we are creating a special part of the "Program" thing called "Main" that the computer will use to start the program. It also says that this part of the program can take some information when it starts which we call "arguments".

9th Line: Console.WriteLine("Hello world!");

  • This line of code says that the program should print the message "Hello world!" to the screen when it starts. This WriteLine method of the Console class adds a newline character at the end of the string, so each call to WriteLine outputs the string on a new line.


4th,6th,8th,10th,11th and 12th Lines: Curly Braces{ }

  • The curly braces mark the beginning and the end of a block of code.

The SUMMARY

In summary, the above code defines a simple console application that outputs the words "Hello world!" to the console when executed.


Congratulations! Now you know the purpose of each code snippet in the above program. That's all for now. Will catch you at the next one. Thank you😍.



Post a Comment

أحدث أقدم
LightBlog
LightBlog