R N REDDY .Net Community - C#
Sunday, 2016-12-04, 11:51 PM
Welcome Guest | RSS
Site menu
Tag Board
500
Our poll
Which .Net class is more interset for you ?
Total of answers: 209
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
 
«  December 2016  »
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
25262728293031

Twitter
 

Entries archive

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