5
Reply

What is the difference between const & static keyword?

sheetal sawant

sheetal sawant

Aug 06, 2010
14k
0

    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

    Sachin Kalia
    January 20, 2011
    0

    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.

    prakash gajera
    October 27, 2010
    0

    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

    Uday Gaikwad
    August 25, 2010
    0

    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.

    Mallika
    August 20, 2010
    0


    sheetal sawant
    August 06, 2010
    0