Bugzilla – Bug 322272
as keyword doesn't work with nullable value types
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by pedro@sobota.net 2006-10-03 09:47:26 MST ---- Differently from csc, using as with a nullable value type doesn't compile: class Global { static void Main() { Console.Write(2 as int?); } } CS0077: The as operator must be used with a reference type ('int?' is a value type). ---- Additional Comments From pedro@sobota.net 2006-10-03 09:51:05 MST ---- Pedro Sobota 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 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 Pedro Sobota wrote: > > 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? Robert Jordan: > Please file a bug. ---- Additional Comments From marek.safar@seznam.cz 2006-10-03 10:46:15 MST ---- *** This bug has been marked as a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=MONO79371 *** This bug was marked DUPLICATE in the database it was moved from. Changing resolution to "MOVED"