0

hi there!)
mates, I had a class - something like that -

public class asd()
{
   public int filed;
}

please tell me - what is the difference between next two ways of memory allocation (as I undestand they both can be compiled...) -
1)

static void Main() {
asd a1 = new asd();
a1.filed= 1;
}

2)

static void Main() {
asd a1 = null;
a1.filed= 1;
}

big thanks in advance)

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by vedro-compota
1

Hello :)
in your 2nd example, the code will not get through. Code will compile, but will be an error on line 3). You will get an error "Object reference not set to an instance of an object.". Thats because a1 was not instantiated yet, and thats why you cannot reach "field" property (or field) on asd class (yet).

1st code looks defenatelly ok.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.