Groups | Blog | Home
all groups > dotnet framework > may 2006 >

dotnet framework : Creating a nullable type using Activator


DerekG
5/19/2006 9:44:01 AM
Hi

I am trying to create an instance of a nullable type using System.Activator
for example

t is passed in from the caller and is the Type info for a nullable type or
can be a standard type i.e string, int etc.

object value = Activator.CreateInstance(t);

value always returns null

Giuseppe Lippolis
5/19/2006 10:10:52 AM
Hello DerekG,
object o = typeof(Nullable<>).MakeGenericType(new Type[] { typeof(int)
});

[quoted text, click to view]

Mattias Sjögren
5/19/2006 6:58:41 PM
[quoted text, click to view]

That makes sense since you haven't specified a value for the instance.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
DerekG
5/22/2006 6:09:01 AM
Hi Giuseppe,

Thanks for the reply, this has helped me solve the problem. Thanks for your
help.

[quoted text, click to view]
AddThis Social Bookmark Button