J
JPS
Can someone please refresh my memory here, but what is the difference
between a Static variable (or method) and a Const?
between a Static variable (or method) and a Const?
JPS said:Can someone please refresh my memory here, but what is the difference
between a Static variable (or method) and a Const?
Martin said:With C#, a static member is a class member:
http://msdn.microsoft.com/en-us/library/98f28cdx(VS.80).aspx
const can be applied to members or to variables to indicate that the
value cannot be modified:
http://msdn.microsoft.com/en-us/library/e6w8fe1b(VS.80).aspx
Less, because you can't mark anything as "const" except static fields,
unlike C++ where variables and access through pointers can be marked "const"
(can't modify the value) anywhere they appear, including function arguments
and even the "this" pointer.
puzzlecracker said:I don't think you have to declare a field static if you specify const.
I believe compilers deduce that automatically.
correct me if I am wrong.
Peter said:[...]
Less, because you can't mark anything as "const" except static
fields, unlike C++ where variables and access through pointers can
be marked "const"
(can't modify the value) anywhere they appear, including function
arguments
and even the "this" pointer.
Small nit: you can mark local variables as "const" as well.