How do i initialize an array using Reflection

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

.



Relevant Pages

  • Re: The Sort Excercise
    ... For example I saw you were using a "Object" array so the original array can ... Here is a plug-in system just to make sure I am clear: ... class MyClass ... Just "load" any derrived class from SomeHandle and let MyClass work with it. ...
    (comp.object)
  • Re: ShowDialog and ArrayList?
    ... P.S. Don't use MyClass as a type name. ... Add a watch for the array. ... >>> I keep an ArrayList in the external class. ... Why the ShowDialog procedure empties array? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: OOP question
    ... to create and array of objects. ... Dim MyObjectas MyClass ... Dim MyObjectas MyClass ... The OP says they already have a method/function named "AddArray, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: C# equivalent of VB.NET Redim Preserve
    ... MyClass myClassInstance = aList; ... If you want more of an array syntax you could derive a wrapper class from ... > Hi Cor, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Array of class and a pointer to it
    ... "John Carson" wrote: ... >> The buttom line, I understand, there is no way to define a pointer to ... >> MyClass and use it to access 2 dimension array of MyClass. ...
    (microsoft.public.vc.language)