(non)nullable types

Nick Sabalausky a at a.a
Fri Feb 13 11:01:57 PST 2009


"Denis Koroskin" <2korden at gmail.com> wrote in message 
news:op.upazx0d4o7cclz at proton.creatstudio.intranet...
> On Fri, 13 Feb 2009 21:43:22 +0300, Nick Sabalausky <a at a.a> wrote:
>>
>> I still like this that someone else mentioned:
>>
>> T? x = something;
>> if(x !is null)
>> {
>>     // x is implicitly "T" here, not "T?"
>> }
>> else
>> {
>>     // handle null condition (x is still "T?")
>> }
>>
>>
>
> Or use an existing syntax:
>
> Foo? foo = ...;
> if (Foo value = foo) {
>     // value is a local variable that is only accessible if foo is not 
> null
> } else {
>     // value is not accessible here
> }

I could live with that, but I'd prefer my suggestion because it wouldn't 
require the creation of an extra label for what's essentially the same 
variable. With your code we'd just end up with a whole bunch of:

Foo? myObj = ...;
if (Foo nonnullMyObj = myObj) //etc...

// or

Foo? nullableMyObj = ...;
if (Foo myObj = nullableMyObj) //etc...

...Which just seems unnecessary to me. 





More information about the Digitalmars-d mailing list