C#- Programming Guide | Starting Phase Learning(4)

Spread the love

Comments and region in C#:

Here we will learn about making the code effective by adding comments and region in c#.
There are different types of comments used in c#:

  1. Single-line comments
  2. Multi-line Comments

Its very useful and professional to use comments before adding any menthods or class so that teh other coders are aware of your code and its associated functions

Single-line comments:
It starts with two forward slashes i.e //
The text following with // is ignored by C# (it wont be executed or debugged).

// This is a single line comment
Console.WriteLine(“Hello tenOclocks!”);

or
Console.WriteLine(“Hello tenOclocks!”);//This is used to print the message

or,
// This is a function to print a message
public void GetMessage()
{
Console.WriteLine(“Hello tenOclocks!”);
}

Multi-line comments start with /* and ends with /. So any texts written between / and */ will be ignored by C#.

/* The function will print the message
to the screen*/
public void GetMessage()
{
Console.WriteLine(“Hello tenOclocks!”);
}

So Seeing both single line and multi line comments under one sample program,
/* Multi
Line
Comment*/
public void GetMessage()
{
Console.WriteLine(“Hello tenOclocks!”); //Single line comment
}

#region

Whenever we write the piece of code under # region, then we define a region that lets you specify a block of code that can be expanded or collapsed using the outlining feature of the Visual Studio Code Editor.
In longer code files, it is convenient to be able to collapse or hide one or more regions so that you can focus on the part of the file that you are currently working on.
A #region block must be terminated with a #endregion directive.

    #region This block gets the welcome text
    /* Multi
       Line 
       Comment*/
    public void GetMessage()
    {
        Console.WriteLine("Hello tenOclocks!"); //Single line comment
    }
    #endregion

DataType and Variables:

string s = “tenOclocks”;
string s1= “tenOclocks”;
string s2= “tenOclocks”;
string _text= “tenOclocks”;
string c_text = “tenOclocks”;


Here, string is a data type and (s , s1 , s2 , _text , c_text ) are variables .
So in an easy language, a variable is a name that we give to a certain dataType.
While coming to the definition it is a named memory location of data type which is used to store data. Its value can be changed and reused many times.

C# | Data Types :

C# is a strongly typed programming language because here, each type of data is predefined as part of the programming language.All then the constants a;nd variables should have their associated data type.

Data types in C# is mainly divided into three categories

  1. Value Data Types
  2. Reference Data Types
  3. Pointer Data Type
Types of DataType in C#

Some Common Types of data types used in C# are:

  1. char : 1 byte -used to assign a single character under ‘ ‘, the default value ‘\0’
  2. short : 2 byte -Stores an integer value, default value 0
  3. int : 4 byte -Stores an integer value , default value 0
  4. long : 8 byte -Stores larger integer value , default value 0
  5. float : 4 byte -Stores larger float type value , default value 0.0F
  6. double: 8 byte -Stores a higher float value , default value 0.0D
  7. decimal: 16 byte – 128-bit precise decimal values with 28-29 significant digits, default value: 0.0M


The detailed analysis of data types will be discussed in the intermediate phase of C# learning.


Leave a Reply

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