C sharp Variables Data Types

Variables in any Programming language  are  the storage Locations where data is stored in Computer Memory. while storing data in variables their  interpretation is controlled with its types.
when we talk about C# we should know That  C# is strongly  typed language.  C sharp compiler  deal variable 's  type that  what type  of variable are they  mean to say retrieve values from variables  or  performing any operation all is done with the type of variables.

Csharp consist of the following Variable data types
  • Boolean Type
  • String Type
  • Integer Type
  • Floating Point 
Before Defining all of the above data type with example program first we should know how to declare variables in C#.
Declaring A variables in C-sharp
Declaring Variables means to assign Values to variables . We can Declare C sharp Variable as follow.
Type   Name = Value ;
first we have to specify type of our variable that we are going to declare then we shouldgive a proper name to our variable in C-sharp Program then  = sign which assign Value our variable. For example.
int z =10;
In above example we have a variable z  of integer type and having value 10.Similarly all of other data type variables can be declared by same rule first type then name and then value of variables.
Boolean Type Variables
In C# Boolean Variables are Declare with keyword bool which have two value True or False For Example.





  static void  Main(string[] args)
        {
            bool contact_no_correct = true;


            if (contact_no_correct == true)
            {
                Console.WriteLine("Number true ");
                Console.ReadLine();


            }


                else Console.WriteLine("Wrong Number");
        }
        }



In the above program we have a bool type variable (contact_no_correct) and who's value is true when run our program our program if the value is true  (contact_no_correct=true) number true will be printed on console window  if we change the value to false  (contact_no_correct=false) wrong number will be printed on screen.

String Type Variables
In C sharp we can Declare String variables  by using the keyword string , name of string variable and its value in double Quotes.

for Example

 
 static void  Main(string[] args)
        {
          string Name ="CsharpTutorialsFree.blogspot.com";
                Console.WriteLine(Name);
                Console.ReadLine();
  }

       

In the above Program we have a string variable Name  when we run the program the value in double quotes will be printed as message on  Console Window. 

Integer Type Variables

In C-sharp Integer type variables are Declared by using  keyword (int) .

for Example  : int a =10; as following program


 static void  Main(string[] args)
        {
                int  a =10;
                Console.WriteLine(a);
                Console.ReadLine();
  }
        }
when we run the program the number 10 will be displayed on screen this is because  we have a memory bucket a and having value 10 stored and that bucket .



Floating Point Variables


Floating point types are used in Csharp programs  when we  need to perform operations requiring fractional representations. They are declared using keyword float.

for Example :


 static void  Main(string[] args)
        {
                float  GPA =3.2;
               Console.WriteLine(GPA);
             Console.ReadLine(); 
  }
        }



In above program we have a  Floating point variable   GPA having value 3.2 when the program runs it will  3.2 on Console window.



No comments:

Post a Comment

Sending SMS Via Windows Form Application Using any Android Smart Phone  Source Code  using System ; using System . C...