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)

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.