当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Object.GetType方法代码示例

本文整理汇总了VB.NET中System.Object.GetType方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Object.GetType方法的具体用法?VB.NET Object.GetType怎么用?VB.NET Object.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。


在下文中一共展示了Object.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: MyBaseClass

' Define a base and a derived class.
Public Class MyBaseClass
End Class 

Public Class MyDerivedClass : Inherits MyBaseClass
End Class 

Public Class Test
    Public Shared Sub Main() 
        Dim base As New MyBaseClass()
        Dim derived As New MyDerivedClass()
        Dim o As Object = derived
        Dim b As MyBaseClass = derived
        
        Console.WriteLine("base.GetType returns {0}", base.GetType())
        Console.WriteLine("derived.GetType returns {0}", derived.GetType())
        Console.WriteLine("Dim o As Object = derived; o.GetType returns {0}", o.GetType())
        Console.WriteLine("Dim b As MyBaseClass = derived; b.Type returns {0}", b.GetType())
    End Sub 
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:20,代码来源:Object.GetType

输出:

base.GetType returns MyBaseClass
derived.GetType returns MyDerivedClass
Dim o As Object = derived; o.GetType returns MyDerivedClass
Dim b As MyBaseClass = derived; b.Type returns MyDerivedClass

示例2: Example

Module Example
   Public Sub Main()
      Dim n1 As Integer = 12
      Dim n2 As Integer = 82
      Dim n3 As Long = 12
      
      Console.WriteLine("n1 and n2 are the same type: {0}",
                        Object.ReferenceEquals(n1.GetType(), n2.GetType()))
      Console.WriteLine("n1 and n3 are the same type: {0}",
                        Object.ReferenceEquals(n1.GetType(), n3.GetType()))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:12,代码来源:Object.GetType

输出:

n1 and n2 are the same type: True
n1 and n3 are the same type: False

示例3: Example

Module Example
   Public Sub Main()
      Dim values() As Object = { 12, CLng(10653), CByte(12), 
                                 CSbyte(-5), 16.3, "string" } 
      For Each value In values
         Dim t AS Type = value.GetType()
         If t.Equals(GetType(Byte))
            Console.WriteLine("{0} is an unsigned byte.", value)
         ElseIf t.Equals(GetType(SByte))
            Console.WriteLine("{0} is a signed byte.", value)
         ElseIf t.Equals(GetType(Integer))   
            Console.WriteLine("{0} is a 32-bit integer.", value)
         ElseIf t.Equals(GetType(Long))   
            Console.WriteLine("{0} is a 32-bit integer.", value)
         ElseIf t.Equals(GetType(Double))
            Console.WriteLine("{0} is a double-precision floating point.", 
                              value)
         Else
            Console.WriteLine("'{0}' is another data type.", value)
         End If   
      Next      
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:23,代码来源:Object.GetType

输出:

12 is a 32-bit integer.
10653 is a 32-bit integer.
12 is an unsigned byte.
-5 is a signed byte.
16.3 is a double-precision floating point.
string' is another data type.


注:本文中的System.Object.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。