[Mono-list] why does gmcs let me assign null to a value type?

Daniel Soto daniel.soto2k at gmail.com
Thu Jan 6 10:58:09 EST 2011


Hmmm, I though that it's because of a behaviour of .NET 3.x, but I compiled
your code in Visual Studio 2010 using .NET 3.0, 3.5 and 4.0 and csc compiler
launches an error that you say.

2011/1/5 Miguel de Icaza <miguel at novell.com>

> I hate this behavior, and I believe it was introduced around c# 3
>
> On Wednesday, January 5, 2011, Eric Slosser <eric.slosser at v-fx.com> wrote:
> > <csharp newbie>
> >
> > I have a C# struct that's defined as
> >
> >         public struct Field : IComparable, IComparable<Field>,
> IEquatable<Field>
> >         {
> >         }
> >
> > When I do this:
> >
> >         Field f = null;
> >
> > I'd expect error CS0037 (can't convert null to 'Field' because it is a
> value type.
> >
> > But when Field is defined in an assembly that was compiled by VisStudio,
> gmcs (v2.8.1.0) is happy to let me assign null to it.
> >
> > Why?
> >
> >
> > _______________________________________________
> > Mono-list maillist  -  Mono-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list
> >
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20110106/42b9032c/attachment.html 


More information about the Mono-list mailing list