本文介绍了VB.NET下后期绑定魔法转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我应该从VB转换部分代码为C#。鉴于以下VB工作线(我只觉得,因为选项未设置严格):
I should convert some code from VB to C#. Given following lines of VB work (I think only because option is not set to strict):
Dim someProp As SomeType
Try
someProp = CType(SomeInstance, Object).SomeProp
' ...
由于后期绑定,该代码下的VB是可能的。当然,下面的下C#是行不通的:
Due to late binding, this code is possible under VB. Of course, following won't work under C#:
SomeType someProp;
try
{
someProp = ((object)SomeInstance).SomeProp;
// ...
我怎么能制定下C#相似的地方?
How could I formulate something similar under C#?
THX任何的窍门
sl3dg3
Thx for any tippssl3dg3
推荐答案
如果你使用C#4.0:
If you're using C# 4.0:
SomeType someProp;
try
{
someProp = ((dynamic)SomeInstance).SomeProp;
// ...
这篇关于VB.NET下后期绑定魔法转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!