|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Creating a nullable type using ActivatorHi
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 >value always returns null 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 Please reply only to the newsgroup. Hello DerekG,
object o = typeof(Nullable<>).MakeGenericType(new Type[] { typeof(int) }); Show quote > 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 > Hi Giuseppe,
Thanks for the reply, this has helped me solve the problem. Thanks for your help. Show quote "Giuseppe Lippolis" wrote: > Hello DerekG, > object o = typeof(Nullable<>).MakeGenericType(new Type[] { typeof(int) > }); > > > 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 > > > > > |
|||||||||||||||||||||||