i have constant int variable defined class variable:
my class defined this:
public class abc : xyz { private const int constantnumber = 600; public abc(): base(constantnumber) {} } would available time calls base constructor (i.e. before calling it's own constructor)?
when defined?
it's available without class being initialized! basically, everywhere constant used, compiler inline value.
for example:
public class constants { public const int foo = 10; static constants() { console.writeline("constants being initialized"); } } class program { static void main() { // won't provoke "constants being initialized" console.writeline(constants.foo); // il equivalent to: // console.writeline(10); } } even static readonly variable, you'd still able use you're using - because it's related type rather instance of type. don't forget const implicitly static (and can't state explicitly).
as side note (mentioned in comments) "embedding" means should use const things are constants. if constants , program above in different assemblies, , constant.foo changed have value of 20, program need recompiled before change usable. isn't case static readonly field, value retrieved @ execution time instead of being embedded @ compile time.
(this affects default values optional parameters.)
Comments
Post a Comment