Reflection: use dynamic type in C#
Forums:
public class Car {
public int Speed { get; set; }
public void IncreaseSpeed(int value) {
Speed += value;
}
}
var carType = Type.GetType("Vehicle.Car");
dynamic car = Activator.CreateInstance(carType);
car.IncreaseSpeed(15);
var speed = car.Speed;
//speed is 15
- Log in to post comments