[Mono-list] Differing nullable behavior

Pedro Sobota pedro at sobota.net
Fri Aug 4 14:22:03 EDT 2006


You are right. In this case, I don't get why csc lets the use of 'as' 
with a nullable value type, if a conventional value type is not 
supported. Should gmcs act like csc, or be coherent?

Unrelated but there is also this curious case where:

static T CheckDBNull<T>(object value) {
    if (value is DBNull) return (T)null; else return (T)value;
}

is not allowed, but

static T CheckDBNull<T>(object value) {
    return (T)((value is DBNull) ? null : value);
}

is, on both compilers!

Pedro

Steve Deobald escreveu:
> Nullables are value types. It seems the .Microsoft NET Framework
> permits this as an exceptional case for usages of the 'as' keyword
> with Nullable<T> on the right. It would seem Mono should do the same
> if it currently does not.
>
> -Steve
>
> On 8/4/06, Pedro Sobota <pedro at sobota.net> wrote:
>> Hi,
>>
>> It seems in Mono, nullables are seen as value types, like the values
>> they contain. This is different from the .Net Framework, for example,
>> this code compiles and works on .Net, but not on Mono:
>>
>> using System;
>>
>> class Global {
>>     static void Main() {
>>         Console.Write(2 as int?);
>>     }
>> }
>>
>> On Mono the result is error CS0077: The as operator must be used with a
>> reference type ('int?' is a value type).
>>
>> Is this intended, or a bug?
>>
>> Pedro
>> _______________________________________________
>> Mono-list maillist  -  Mono-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>>
>



More information about the Mono-list mailing list