Difference between member variable and local variable in C#

Member variables:

  Definition: Variables defined in a class are called member variables

  Scope: Valid in the entire class

  Classification: Member variables can be divided into instance variables and static variables (plus the keyword static)

class test1
      int   a =   33 ;     // Instance variable, valid in class test1 
      static  int b = 45 ;    // Static variable, valid in the whole program, can be called in other classes           
}

 

local variable:

  Definition: Variables defined in a method are called local variables

  Scope: Effective within the currently defined method, the method call is destroyed, and cannot be called in other classes

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325220030&siteId=291194637