Interviews - C# Corner

sheetal sawant
What is the difference between const & static keyword?
By sheetal sawant in OOP/OOD onAug 06 2010
  • Sachin Kalia
    Jan, 2011 20

    Hi All

    Constant variable can not be modified after it defines and it can not be change the value of const. variables.if you try to change it it prompts you error msg.
    Constant variables declares with const. keyword in c#

    A variable declared static in a function retains its state between calls to that function.

    When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class.

    Static variable declares with static keyword in c#.

    Warm Regards
    Sachin Kalia

    • 0
  • prakash gajera
    Oct, 2010 27

    Static object or variable is stored on the data segment area of memory and the same value is get shared by all the objects/variables While Const is Just a name of that assigned value which cant be changed.and replaced at all the location by compiler while compilation.

    • 0
  • Uday Gaikwad
    Aug, 2010 25

    The copy of static variable remains same or its shared among all the instance objects of a class

    constant variable can not be modified after it defines and it can not be change any how throughout the program

    • 0
  • Mallika
    Aug, 2010 20

    refernce: msdn

    A variable declared static in a function retains its state between calls to that function.

    When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. When modifying a member function in a class declaration, the static keyword specifies that the function accesses only static members.

    The const keyword specifies that a variable's value is constant and tells the compiler to prevent the programmer from modifying it.

    Declaring a member function with the const keyword specifies that the function is a "read-only" function that does not modify the object for which it is called.

    • 0
  • sheetal sawant
    Aug, 2010 6


    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS