Search notes:

System.Activator (class)

System.Activator allows to dynamically create types, given an instance of System.Type.
This class contains two methods: CreateInstance and CreateInstanceFrom (although with quite some overloads).

Example

The following simple C# example tries to demonstrate how Activator might be used.
using System;

namespace Example {

   class XYZ {

      public int    num;
      public string txt;

      public XYZ() {
         num = 42;
         txt ="Hello World";
      }

      public XYZ(int num_, string txt_) {
         num = num_;
         txt = txt_;
      }

   }

   class Prg {

      static void Main() {
         Type   typ = Type.GetType("Example.XYZ");

         if (typ == null) {
            Console.WriteLine("Could not create Example.XYZ");
            return;
         }

         Object obj1 = Activator.CreateInstance(typ);
         Object obj2 = Activator.CreateInstance(typ, new object[] {99, "Foo bar baz"});

         Console.WriteLine("  num = {0}, txt = {1}", (obj1 as XYZ).num, (obj1 as XYZ).txt);
         Console.WriteLine("  num = {0}, txt = {1}", (obj2 as XYZ).num, (obj2 as XYZ).txt);
      }

   }
}
Github repository .NET-API, path: /System/Activator/intro.cs
When executed, this sample prints
num = 42, txt = Hello World
num = 99, txt = Foo bar baz

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1758201010, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/dot-net/namespaces-classes/System/Activator/index(88): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78