Sunday, 2024-04-28, 12:22 PM
Welcome Guest | RSS
Site menu
Tag Board
500
Our poll
Rate my site
Total of answers: 148
Statistics

Total online: 1
Guests: 1
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
 
«  April 2024  »
SuMoTuWeThFrSa
 123456
78910111213
14151617181920
21222324252627
282930

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