[Mono-devel-list] Exception in small generic c# program
Martin Willemoes Hansen
mwh at sysrq.dk
Wed May 5 17:14:48 EDT 2004
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
--------------------------------------------------------
More information about the Mono-devel-list
mailing list