Re: Casting null to nullable
Rich Armstrong <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <[email protected]> |
I'm aware of one situation that requires an explicit cast:
// This produces an error "Type of conditional expression
// cannot be determined because there is no implicit conversion
// between 'int' and '<null>'"
int? nullableInt = someCondition ? 0 : null;
// This compiles without error
int? nullableInt = someCondition ? 0 : (int?)null;
I'll reserve judgment on how intuitive the requirement may or not be.
> Date: Thu, 15 Nov 2007 10:27:42 +0000> From: [email protected]> Subject: Re: [DOTNET-CLR] Casting null to nullable> To: [email protected]> > > I find this requirement quite unintuitive and clumsy. Is there anything> > to be said in its defence? I thought nullable types were supposed> > to save us this kind of friction.> > Could you say exactly what requirement you mean?> > You can do:> > int? x = null;> > with no explicit cast, for instance.> > Jon> > ===================================> This list is hosted by DevelopMentor® http://www.develop.com> > View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com