LEARN C-SHARP IDENTIFIERS AND KEYWORDS , DATA TYPE , VARIABLES , CONSTANTS ( class 2)

what is identifiers and keywords:

In C# , an identifiers is a sequence of character used in identify the variable , constant , or any user defined programming element. An identifiers starts with a letter or an underscore and end with a character. C# identifiers are case sensitive , which means , the variable names sum , Sum , and SUM all three are different from each other.

you must remember the following rules while creating identifiers:


  1. An identifiers must begin either with a letter or underscore.
  2. An identifiers cane have letter , digits , and underscore.
  3. An identifiers must not be a reserved word ( keyword in C# ).
  4. An identifiers must be a complete word without any blank space.
Keyword are the reserved word whose meanings are the predefined to the C# compiler. In other words , keywords are those words , which are the reserved by the C# compiler to be used for the specific task. You can not use keyword as variable , method , and properties because they are already defined to the compiler to perform specific functionalists.

data type , variables and constant:

C# supports a rich and varied  selection of data type , from built in types , such as integers , strings , to user-ned types , such as enumeration , structure , and classes. 

when declaring with these data types , you must remember the following points :
  1. All variables , whether user-define or built-in , can be used as object anywhere in a program.
  2. All variables in a program are automatically initialized to default value by the system when they are declared.
constant :

similar to a variable , a constant is also used to store a values. however , unlike a variable , the value of a constant does not change during the execution of a program. A variable is declared as constant by using const keyword.

the following code shows how to use constant variable in your application:



 const double e = 2.78516542;
            const int x = 100;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace constant_variables.cs
{
    class Program
    {
        static void Main(string[] args)
        {
            const double pi = 3.17; // declaring a constant variable.
            int r;
            Console.WriteLine("enter the value of r");
            r = Convert.ToInt32(Console.ReadLine());
            double circlearea = pi * r * r;
            Console.WriteLine("the area of circle is:" + circlearea);
            Console.ReadKey();
        }
    }
}


0 comments: