Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.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
c#-如何在组合框或列表中获取网络适配器名称?_C#_Class_Combobox_Network Programming - Fatal编程技术网

c#-如何在组合框或列表中获取网络适配器名称?

c#-如何在组合框或列表中获取网络适配器名称?,c#,class,combobox,network-programming,C#,Class,Combobox,Network Programming,我是一个初学者程序员,我正在制作一个小型winform应用程序来快速更改我的IP地址(从DHCP到静态)。我正在使用netsh命令 我正在努力获取网络适配器的名称并将其添加到组合框中。到目前为止,我只在节目开始时添加了这一行: using System.Net.NetworkInformation; 我尝试了这行代码,但它只返回一个适配器名称: foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()

我是一个初学者程序员,我正在制作一个小型winform应用程序来快速更改我的IP地址(从DHCP到静态)。我正在使用netsh命令

我正在努力获取网络适配器的名称并将其添加到组合框中。到目前为止,我只在节目开始时添加了这一行:

using System.Net.NetworkInformation;
我尝试了这行代码,但它只返回一个适配器名称:

foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) 
{ 
    value = nic.Name; 
}

谢谢你的帮助

谢谢@TaW,我终于有了这个结论:

List<string> AdapterList = new List<string>();
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                AdapterList.Add(nic.Name);
            }
            networkAdapterList.DataSource = AdapterList;
列表适配器列表=新列表();
foreach(NetworkInterface.GetAllNetworkInterfaces()中的NetworkInterface nic)
{
AdapterList.Add(网卡名称);
}
networkAdapterList.DataSource=AdapterList;

它工作得非常好

计算机上有多个网络“适配器”吗?嗯,您将所有名称分配给同一个变量,因此无论有多少个,它看起来都像一个。将它们添加到列表中!如果@TaW是正确的,那么调试您自己的代码就可以很容易地解开谜团。