Saturday, 2024-11-16, 10:31 AM
Welcome Guest | RSS
Site menu
Tag Board
500
Our poll
Which .Net class is more interset for you ?
Total of answers: 225
Statistics

Total online: 5
Guests: 5
Users: 0

08-12-2010


Variable: Variable is representing a temporary value, the value can be changed.

Syntax: To declare variable
               <data type> <variable name> = <value>;

Eg: int a = 10; 
      string s = "Stahya";  

Eg: for variable:
    void main(---)
        {
            int a = 10;
            string s = "Sathya";
            Console.WriteLine(a);
            Console.WriteLine(s);
            Console.ReadLine();
         }
Output: 10
              Sathya

Eg: for case sensitive:

    void main(---)
        {
           int a = 10;
           Console.WriteLine(a);
           Console.ReadLine();
        }
Output: Output for above program is error because C#.Net is a case sensitive language.

Local variables: The variables which is declared within a function can be called aslocal variable.

Local variable should be initialized at the time of declaration otherwise compiler will generate an error.

Eg: for local variable:
    void main(---)
        {
          int a;
          Console.WriteLine(a);
          Console.ReadLine();
        }
Output: The above program will generate an error because 'a' is a local variable, local variables should be initialized at the time of declaration like below:              int a = 10;

Eg: Print a variable value with user defined string:
    void main(---)
        {
          int a = 10;
         Console.WriteLine("a value is " +a);
         Console.ReadLine();
        }
Output: a value is 10

To write the comments we will use two forwarding slashes(//).

Eg: To print multiple user defined message with variable values:
    void main(---)
        {
           int a = 10;
           int b = 20;
           string s = "Sathya";
           Console.WriteLine("a value is " +a);
           Console.WriteLine("b value is " +b);
           Console.WriteLine("s value is " +s);
           Console.ReadLine();
        }
Output: a value is 10
              b value is 20
              s value is sathya

Eg: To accept input from the user:
    void main(--)
         {
           Console.WriteLine("Enter your name");
           string s = Console.ReadLine();
           Console.WriteLine("Your name is " +s);
           Console.ReadLine();
         }
Output: Enter your name
              Sathya
              Your name is Sathya 





Search

Time
 

 

Calendar
 
«  November 2024  »
SuMoTuWeThFrSa
     12
3456789
10111213141516
17181920212223
24252627282930

Twitter
 

Entries archive

Copyright R N Reddy © 2024Developed by Nagendra, Venkat, Vijaya and Yaswanth
Get free updates as SMS to your mobile. Just register by clicking here