C#2.0 Nullable types issue

  • Thread starter Thread starter cody
  • Start date Start date
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() ?? "";
 
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() ?? "";
 
Thank you. The docs say an InvalidOperationException will be thrown.
I'd use a new Excpeption, preferably derived from InvalidOperationException.
 
Back
Top