C# 按名称而不是按类型c获取网络接口#

C# 按名称而不是按类型c获取网络接口#,c#,C#,我有按类型获取网络接口名称的代码(仅用于ex=检测无线适配器) private void Form1\u加载(对象发送方,事件参数e) { ///使用Linq检测无线适配器 IEnumerable NIC=NetworkInterface.GetAllNetworkInterfaces()。其中(网络=>network.NetworkInterfaceType==NetworkInterfaceType.wireless8021&&network.Name==“Microsoft托管网络虚拟适配

我有按类型获取网络接口名称的代码(仅用于ex=检测无线适配器)

private void Form1\u加载(对象发送方,事件参数e)
{
///使用Linq检测无线适配器
IEnumerable NIC=NetworkInterface.GetAllNetworkInterfaces()。其中(网络=>network.NetworkInterfaceType==NetworkInterfaceType.wireless8021&&network.Name==“Microsoft托管网络虚拟适配器”);
////修改为使用以下Linq语句仅选择活动的无线适配器
////.Where(network=>network.OperationalStatus==OperationalStatus.Up&&network.NetworkInterfaceType==NetworkInterfaceType.wireless8021)
////要检测所有以太网和无线适配器,可以使用以下语句
////其中(network=>network.OperationalStatus==OperationalStatus.Up&&(network.NetworkInterfaceType==NetworkInterfaceType.Ethernet | | NetworkInterfaceType==NetworkInterfaceType.Wireless80211))
///将项目添加到下拉列表
cmbadtors.DisplayMember=“说明”;
CMBAddotors.ValueMember=“Id”;
foreach(NIC中的网络接口项)
{
CMBAddotors.Items.Add(item);
}
如果(cmbadtors.Items.Count>0)
CMBADTORS.SelectedIndex=0;
}
私有无效CMBAddators\u选择的索引已更改(对象发送者,事件参数e)
{
尝试
{
if(cmbadtors.SelectedItem为网络接口)
{
slectedNic=cmbadtors.SelectedItem作为网络接口;
uniCastIPInfo=null;
///填充IPv4地址
if(slectedNic!=null&&slectedNic.GetIPProperties().unicastaddress!=null)
{
UnicastipAddressInformation集合ipInfo=slectedNic.GetIPProperties().UnicastAddresses;
foreach(ipInfo中的UnicastIPAddressInformation项)
{
if(item.Address.AddressFamily==System.Net.Sockets.AddressFamily.InterNetwork)
{
lblIP.Text=item.Address.ToString();
uniCastIPInfo=项目;
打破
}
}
}
带宽计算器(uniCastIPInfo、slectedNic);
wirelssUpdator.Enabled=true;
}
}
捕获(例外情况除外)
{               
投掷;
}
}
这是密码

但我想让它按名称获取网络无线适配器

for ex=如果适配器的名称为“Microsoft托管网络虚拟适配器”

因此,如果我指定了该选项,则仅检测此适配器(如果可用)

请帮忙

这个怎么样

 IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces().Where(network => network.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 && network.Name == "name you want");


foreach(var nIf in nics)
 cmbAdaptors.Items.Add(nIf.Name);
IEnumerable NIC=NetworkInterface.GetAllNetworkInterfaces().Where(网络=>network.NetworkInterfaceType==NetworkInterfaceType.wireless8021&&network.Name==“您想要的名称”);
foreach(NIC中的变量nIf)
CMB适配器.Items.Add(nIf.Name);
这个怎么样

 IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces().Where(network => network.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 && network.Name == "name you want");


foreach(var nIf in nics)
 cmbAdaptors.Items.Add(nIf.Name);
IEnumerable NIC=NetworkInterface.GetAllNetworkInterfaces().Where(网络=>network.NetworkInterfaceType==NetworkInterfaceType.wireless8021&&network.Name==“您想要的名称”);
foreach(NIC中的变量nIf)
CMB适配器.Items.Add(nIf.Name);

给我们更多的代码,而不仅仅是一行代码。请尝试我编辑的回答,问题是CMBAddators显示的是类型而不是名称?在我上面的评论中,我要求您也尝试在绑定CMBAddators之前添加。DisplayMember=“Name”;cmbadapters.ValueMember=“Name”;我已经得到了一个解决方案,它检测所有无线适配器,我将在特定适配器属性上添加焦点,使其与我想要的类似,我将禁用该组合框。在linq查询之后,为了显示名称,请执行此操作foreach(NIC中的var face)CMBAdapters.Items.add(face.Name);刚刚测试过!给我们更多的代码,而不仅仅是一行。请尝试我编辑的回答,问题是CMBAddators显示的是类型而不是名称?在我上面的评论中,我要求您也尝试在绑定CMBAddators之前添加。DisplayMember=“Name”;cmbadapters.ValueMember=“Name”;我已经得到了一个解决方案,它检测所有无线适配器,我将在特定适配器属性上添加焦点,使其与我想要的类似,我将禁用该组合框。在linq查询之后,为了显示名称,请执行此操作foreach(NIC中的var face)CMBAdapters.Items.add(face.Name);刚刚测试过!