将某些vb.net代码转换为c#
我正在将类库从vb.net转换为C#。一切都很好,但在我转换的一个函数中,我遇到了问题 VB.NET代码将某些vb.net代码转换为c#,c#,vb.net,C#,Vb.net,我正在将类库从vb.net转换为C#。一切都很好,但在我转换的一个函数中,我遇到了问题 VB.NET代码 Protected Function CloseButtonOfTabPage(ByVal tp As TabPage) As PictureBox Return (From item In CloseButtonCollection Where item.Value Is tp Select item.Key).FirstOrDefault End Function 其中Clos
Protected Function CloseButtonOfTabPage(ByVal tp As TabPage) As PictureBox
Return (From item In CloseButtonCollection Where item.Value Is tp Select item.Key).FirstOrDefault
End Function
其中CloseButtonOfTabPage是System.Collection.Generic.Dictionary
转换此代码时遇到问题。有人能帮我吗?假设你的字典有正确的键和值类型,C#中的这段代码应该可以:
protected PictureBox CloseButtonOfTabPage(TabPage tp)
{
return CloseButtonCollection
.Where(item => item.Value == tp)
.Select(item => item.Key).FirstOrDefault();
}
(你的意思肯定是
CloseButtonCollection
是一本字典,而不是closebuttonoftabage
)。也是一个可能的代码示例:(使用LINQ)
实际的代码行代码可以通过使关键字小写来转换。请尝试此工具。。。它几乎总是有效的。。。
protected PictureBox CloseButtonOfTabPage(TabPage tp)
{
return (from item in CloseButtonCollection
where item.Value == tp
select item.Key).FirstOrDefault();
}