hi
Can any one help me , can i initilize instance variable without constructor if it is possible than how , if it is not possible why what is the reason of that...?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jun 9, 2011, 4:30 AM
class MyClass
{
public int MyInt = 3;
public string MyString = "Hello";
// etc
}
If you don't initialize them , then they have their default values of 0 (numbers), false (bool) or null (reference types).
Notice though that you can't do this for structs. You have to use the constructor.