小编Dus*_*san的帖子

网络接口列表、抽象类型或接口

我有一个程序列出了硬盘驱动器和网络接口,如下图所示: 网络接口列表

如果我单击硬盘名称,我可以在文本框中看到驱动器类型。这工作正常。但是,如果我在网络接口上尝试此代码,它不起作用。它给出了错误 CS0144:无法创建抽象类型或接口“NetworkInterface”的实例

这是代码:

 private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            textBox1.Text = "";
            DriveInfo[] Drives = DriveInfo.GetDrives();
            foreach (DriveInfo drv in Drives)
            {
                listBox1.Items.Add(drv.Name);
            }
        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            String strDrive = (string)listBox1.SelectedItem;
            DriveInfo drive = new DriveInfo(strDrive);

            textBox1.Text = drive.DriveType.ToString();
        }
Run Code Online (Sandbox Code Playgroud)

这里是不工作的网络接口:

private void button3_Click(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            textBox2.Text = "";
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                listBox2.Items.Add(adapter.Name);
            }
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        { …
Run Code Online (Sandbox Code Playgroud)

c# winforms network-interface

0
推荐指数
1
解决办法
115
查看次数

标签 统计

c# ×1

network-interface ×1

winforms ×1