[Mono-devel-list]Re: [Mono-devel-list] Exception in small generic c# program

marek safar marek.safar at seznam.cz
Thu May 6 02:22:27 EDT 2004


Hi,

Yes, it is a bug.

BTW: Second using is useless.

Marek


> Hello!
> 
> When running the program below I get an exception:
> 
> using System;
> using System.Collections;
> 
> class Hello {
> 
> 	static void Main()
> 	{
> 		MyGenericClass<int> foo = new MyGenericClass<int>();
> 		foo.Generic = 10;
> 		Console.WriteLine (foo);
> 
> 		MyGenericClass<string> bar = 
> 				new MyGenericClass<string>();
> 		bar.Generic = "Hello, World!";
> 		Console.WriteLine (bar);
> 
> 		MyGenericClass<double> baz = 
> 				new MyGenericClass<double>();
> 		baz.Generic = 10.5D;
> 		Console.WriteLine (baz);
> 	}
> }
> 
> class MyGenericClass<T> {
> 
> 	T var;
> 
> 	public T Generic {
> 		set { var = value; }
> 	}
> 
> 	public override string ToString()
> 	{
> 		return var.GetType().ToString();
> 	}
> 
> }
> 
> This is the output I get when running the program.
> I use Mono Beta1
> 
> System.Int32
> System.String
>  
> Unhandled Exception: System.NullReferenceException: A null value was
> found where an object instance was required.
> in (unmanaged) MyGenericClass!1:ToString ()
> in <0x0001d> System.IO.TextWriter:Write (object)
> in <0x0000e> System.IO.TextWriter:WriteLine (object)
> in <0x00035> System.IO.SynchronizedWriter:WriteLine (object)
> in <0x0001a> System.Console:WriteLine (object)
> in <0x000d6> Hello:Main ()
>  
> Lagersegmentfejl
> 
> Can someone here verify if this a bug?
> 
> -- 
> Martin Willemoes Hansen
> 
> --------------------------------------------------------
> E-Mail	mwh at sysrq.dk	Website	mwh.sysrq.dk
> IRC     MWH, freenode.net
> --------------------------------------------------------              
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

____________________________________________________________
Obchodní dům.cz - široký sortiment domácích spotřebičů a elektroniky, výrazné slevy. Navštivte 
http://ad.seznam.cz/clickthru?spotId=73742&section=/



More information about the Mono-devel-list mailing list