C#2.0 Nullable types issue

C

cody

What happens when:

int? n = null;
int i = n;

I suppose and NullReferenceException or similar should be thrown but in the
official documents nothing is said about that.

However I find the nullable types one of the absolutely greatest inventions
in programming languages ever.
I especially like the coelescing operator ?? because I find myself very
often to write something like
Text = obj==null ? "" : obj.ToString(); which will then be Text =
obj.ToString() ?? "";
 
S

Shiva

Hi,
It is in a separate doc -
http://download.microsoft.com/downl...e-9e5e-f87a44af3db9/NullableTypesProposal.pdf

What happens when:

int? n = null;
int i = n;

I suppose and NullReferenceException or similar should be thrown but in the
official documents nothing is said about that.

However I find the nullable types one of the absolutely greatest inventions
in programming languages ever.
I especially like the coelescing operator ?? because I find myself very
often to write something like
Text = obj==null ? "" : obj.ToString(); which will then be Text =
obj.ToString() ?? "";
 
C

cody

Thank you. The docs say an InvalidOperationException will be thrown.
I'd use a new Excpeption, preferably derived from InvalidOperationException.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top