What is the difference between Const and Static in C#? -
i eager know difference between const variable , static variable.
as far know const static , can not accessed on instance variable that's same static , difference between them ?
please explain ...
const
fields can hold value types or system.string
. must immutable , resolvable @ compile-time.
static readonly
fields can , hold reference types, (other strings) can created @ runtime. these can (but shouldn't) mutable types; thing cannot change reference itself.
if need maintain "constant" set of instances reference types, set of public static readonly
fields, such members of system.drawing.systemcolors.
last not least, initialization of readonly
field can deferred until execution of constructor, means though can written to once, not have initialized exact same value. true constants declared const
can ever have single value (specified @ compile time).
Comments
Post a Comment