Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var instance = (Person) Activator.CreateInstance(typeof(Person), "Pesho");
- //
- Type type = Type.GetType("Reflection.Demo.Ferrari");
- var obj = Activator.CreateInstance(type, new object[]{ }) as Ferrari; // create instance with reflection
- Console.WriteLine(obj.Name);
- //
- string make = Console.ReadLine();
- Type type = Type.GetType($"Reflection.Demo.{make}");
- var obj = Activator.CreateInstance(type) as Car; // create instance with reflection
- Console.WriteLine(obj.Name);
- //
- Type type = Type.GetType($"System.Text.StringBuilder");
- StringBuilder sbInstCapacity = (StringBuilder)Activator.CreateInstance(type, new object[] { 10 });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement