Types of variables in C#



Types of variables:-
1)      Local variable
2)      Class level variable
3)      Block level variable

1. Local variable:
  •  These are declared and accessible within a function only.
  •  Syntax:
                            void fun1()
                            {
                               double d;
                            }

2. Class level variable:
  •  These are declared in the class.
  •  Accessible within the same class only.
  •  Syntax:
                              class class1
                              {
                                 double d;
                              }
3. Block level variable:
  •  These are declared and accessible within the same block.
  •  Ex: if block, else block, while block, for block. etc.
  •  Syntax:
                                if (condition)
                                {
                                      double d;
                                }
Note:
  •  In c#, no 'global variables'.
  • Access specifier is not applicable for local variables & block level variables.

No comments:

Post a Comment