Array.CreateInstance Method
using System;
using System.Reflection;
public class Starter {
public static void Main(string[] argv) {
Assembly executing = Assembly.GetExecutingAssembly();
Type t = executing.GetType(argv[0]);
Array zArray = Array.CreateInstance(t, argv.Length - 2);
for (int count = 2; count < argv.Length; ++count) {
System.Object obj = Activator.CreateInstance(t, new object[] {argv[count]});
zArray.SetValue(obj, count - 2);
}
foreach (object item in zArray) {
MethodInfo m = t.GetMethod(argv[1]);
m.Invoke(item, null);
}
}
}
public class MyClass {
public MyClass(string info) {
m_Info = "MyClass " + info;
}
public void ShowInfo() {
Console.WriteLine(m_Info);
}
private string m_Info;
}
public class YClass {
public YClass(string info) {
m_Info = "YClass " + info;
}
public void ShowInfo() {
Console.WriteLine(m_Info);
}
private string m_Info;
}
public class XClass {
public XClass(string info) {
m_Info = "XClass " + info;
}
public void ShowInfo() {
Console.WriteLine(m_Info);
}
private string m_Info;
}
Related examples in the same category