c# - what does this mean? (about class and instance) -
using system; class program { static void main() { haha haha1; } } class haha { int a; int b; public haha(int a, int b) { this.a = a; this.b = b; } }
i know if want make instance, should write code such as:
haha haha1 = new haha(1,2);
but when write just
haha haha1;
there's no compile error.
what haha haha1;
mean? isn't wrong code?
it not wrong code. variable declaration.
haha haha1;
simply declares variable named haha1 has type haha. variable not assigned value.
when instantiate object new keyword:
haha1 = new haha();
the variable refers object created
Comments
Post a Comment