本文整理汇总了VB.NET中System.Activator类的典型用法代码示例。如果您正苦于以下问题:VB.NET Activator类的具体用法?VB.NET Activator怎么用?VB.NET Activator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Activator类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Module1
' 导入命名空间
Imports System.Reflection
Imports System.Text
Module Module1
Sub Main()
' Create an instance of the StringBuilder type using
' Activator.CreateInstance.
Dim o As Object = Activator.CreateInstance(GetType(StringBuilder))
' Append a string into the StringBuilder object and display the
' StringBuilder.
Dim sb As StringBuilder = CType(o, StringBuilder)
sb.Append("Hello, there.")
Console.WriteLine(sb)
' Create an instance of the SomeType class that is defined in this assembly.
Dim oh As System.Runtime.Remoting.ObjectHandle = _
Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase, _
GetType(SomeType).FullName)
' Call an instance method defined by the SomeType type using this object.
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
输出:
Hello, there. 100 / 5 = 20