C# Activator Jun 2026

string typeName = "System.DateTime, mscorlib"; DateTime dt = (DateTime)Activator.CreateInstance(Type.GetType(typeName), new object[] { 2024, 12, 31 });

Activator uses reflection and is slower than direct new or compiled delegates. For performance-critical repeated instantiation, cache delegates or use FormatterServices.GetUninitializedObject (advanced scenarios). c# activator

class Program { static void Main(string[] args) { // Get the type of MyClass Type type = typeof(MyClass); string typeName = "System