How do i initialize an array using Reflection
- From: "Kishore" <vkbulusu@xxxxxxxxx>
- Date: 8 Mar 2007 16:42:05 -0800
Hi
I have a class (type - MyClass). I need to create an instance of this
class and then create an array of type MyClass and intialize this
array with the instance.
I am able to create the class and array but not sure how to
initialize.
Type myClassType = Type.GetType("MyClass,MyAssembly");
ConstructorInfo cinfo = myClassType.GetConstructor(new Type[]{});
object myClassObj = cinfo.Invoke(null);
Type myClassArrayType = Type.GetType("MyClass[], MyAssembly");
cinfo = myClassArrayType.GetConstructor(new Type[]{typeof(int)});
object myClassArray = cinfo.Invoke(new object[]{1});
//HOW CAN I DO myClassArray[0] = myClassObj using Reflection.
Please suggest
Thanks
.
- Follow-Ups:
- Re: How do i initialize an array using Reflection
- From: Oliver Sturm
- Re: How do i initialize an array using Reflection
- Prev by Date: Re: Using a thirdparty ActiveX control in C#
- Next by Date: Remoting & Security
- Previous by thread: Re: Using a thirdparty ActiveX control in C#
- Next by thread: Re: How do i initialize an array using Reflection
- Index(es):
Relevant Pages
|