C# 什么';s是C的“替代品”;加上;代码块(仅限VB.NET功能)?

C# 什么';s是C的“替代品”;加上;代码块(仅限VB.NET功能)?,c#,vb.net,vb.net-to-c#,C#,Vb.net,Vb.net To C#,我知道C#不支持“With”代码块。但是,如何用C#编写以下代码块: 谢谢 没有“正确的方法”,因为与不是C#功能-没有等价物 使用命名变量: string SomeString = String.Empty; var lookups = Lookups.LookupManager.Lookups.Item(Lookups.SomeLists.GetType()) as Lookups.SomeLists; if(lookups != null)

我知道C#不支持“With”代码块。但是,如何用C#编写以下代码块:

谢谢

没有“正确的方法”,因为
不是C#功能-没有等价物

使用命名变量:

string SomeString = String.Empty;    
var lookups = Lookups.LookupManager.Lookups.Item(Lookups.SomeLists.GetType()) 
                    as Lookups.SomeLists;
if(lookups != null)
{
    SomeString = lookups.SomeDataTableProperty.SomeColumn.ColumnName;
}
没有“正确的方法”,因为
With
不是C#特性-没有等价物

使用命名变量:

string SomeString = String.Empty;    
var lookups = Lookups.LookupManager.Lookups.Item(Lookups.SomeLists.GetType()) 
                    as Lookups.SomeLists;
if(lookups != null)
{
    SomeString = lookups.SomeDataTableProperty.SomeColumn.ColumnName;
}

VB的
With
语法保存了实例变量的键入。由于C#没有“with”结构,您必须自己键入它:

更改此VB

With instance
   somestring = .Property
End With
进入这个C#


VB的
With
语法保存了实例变量的键入。由于C#没有“with”结构,您必须自己键入它:

更改此VB

With instance
   somestring = .Property
End With
进入这个C#


我得到了这样一个错误“没有方法'GetType'的重载需要1个参数”。这也不起作用。但这是可行的:var lookups=(lookups.SomeLists)(lookups.LookupManager.lookups[typeof(lookups.SomeLists)])。再次感谢!这更像是一个类型转换问题。我得到了这个错误“没有方法'GetType'的重载需要1个参数”。这也不起作用。但这是可行的:var lookups=(lookups.SomeLists)(lookups.LookupManager.lookups[typeof(lookups.SomeLists)])。再次感谢!这更像是一个类型转换问题。