Welcome to RightHand's community place Sign in | | Help

Assigning default values to fields trivia

class Tubo { bool value; bool TuboTubo() { return value; } }

Will this piece of code compile (answer without compiling, please Smile)?

Published 15. november 2007 11:13 by Miha Markic
Filed under:

Comments

# re: Assigning default values to fields trivia

15. november 2007 12:07 by Giuseppe
yes. cuz the variable is declared on class level and will be initialized automatically.

# re: Assigning default values to fields trivia

15. november 2007 21:13 by Kalpesh
Questions like this are always difficult to answer without understanding of how language is supposed to behave. I think, this should raise compiler error for "use of unassigned variable"

# re: Assigning default values to fields trivia

16. november 2007 13:56 by Miha Markic

Giuseppe got it right. This time the field is set to its default value.

@Kalpesh: otoh it is fun and we all learn :-)

Anonymous comments are disabled