Activator Class : Activator « Reflection « VB.Net






Activator Class

 

Imports System.Reflection
Imports System.Text

Module Module1
    Sub Main()
        Dim o As Object = Activator.CreateInstance(GetType(StringBuilder))
        Dim sb As StringBuilder = CType(o, StringBuilder)
        sb.Append("Hello, there.")
        Console.WriteLine(sb)
        Dim oh As System.Runtime.Remoting.ObjectHandle = Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase,GetType(SomeType).FullName)

        Dim st As SomeType = CType(oh.Unwrap(), SomeType)
        st.DoSomething(5)
    End Sub
    Class SomeType
        Public Sub DoSomething(ByVal x As Int32)
            Console.WriteLine("100 / {0} = {1}", x, 100 \ x)
        End Sub
    End Class
End Module

   
  








Related examples in the same category

1.Activator.CreateInstance creates specified type using that type's default constructor.