c# - Why must initialization value of field members be determinable at compile time? -


1) Why should the initial value of the field members be compiled when compiling time?

2) But if the initial value should be determined to compile, then why am I able to start a ab field in the context of an object:

  class A {B b = new B (); } Class B {}  

thanks

I'm a little cache ; There is no such rule for the field, in particular, the fields are clearly started by anyway - either by your code or by default, the only corner-contrast strategy field Initialization is understood, in which the strat is considered to be complete before all fields must be assigned.

I wonder if you are talking about the "fixed assignment" of the variable in methods; I.e.

  zero fu () {int i; Console.WriteLine (i); // is not valid; I did not assign I = 1; Console.WriteLine (i); // value will be}}  

This is because the value for the method variable sometimes does not suffer from random values ​​which are taken from the stack. Indeed, an IL is marked, that means the locals are wiped out - and the IIRC C # compiler contains this marker anyway ... but the Language Speech method variable says that < Strong> should certainly assigned.


In the case of an example, that area-start essentially becomes a part of the common constructor code. But you will never pay attention to it.


Comments

Post a Comment

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -