代码之家  ›  专栏  ›  技术社区  ›  Shimmy Weitzhandler 500 - Internal Server Error

它是否提高了低级别类型的性能铸造?

  •  0
  • Shimmy Weitzhandler 500 - Internal Server Error  · 技术社区  · 14 年前

    考虑一下这个例子

    Interface IInterface
        Property MyProperty
    End Interface
    
    Class MyClassy : Implements IInterface
        Public Property MyProperty
    End Class
    
    Class MyClassy2 : Inherits MyClassy
    End MyClassy
    Class MyClassy3 : Inherits MyClassy
    End MyClassy    
    Class MyClassy4 : Inherits MyClassy
    End MyClassy
    Class MyClassy5 : Inherits MyClassy
    End MyClassy
    
    Private Sub MyHandler(sender As Object, e As EventArgs)
        'Here is my question:
    
        Dim lowLevel = DirectCast(sender, IInterface).MyProperty
    
        'vs.
    
        Dim highLevel = DirectCast(sender, MyClassy5).MyProperty  
    
    End Sub
    

    类型 sender 在上面的例子中是 MyClassy5 .

    这两种铸件的性能有什么不同吗?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Vladislav Rastrusny    14 年前

    由于DirectCast不使用任何运行时帮助程序来执行转换,因此性能应该相同。但你不应该在意,除非你每秒做数百万次的投射。