Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将某些vb.net代码转换为c#_C#_Vb.net - Fatal编程技术网

将某些vb.net代码转换为c#

将某些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

我正在将类库从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
其中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();
}