I would change the code you have:
public string net_adapters()
{
string value = string.Empty;
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
value = nic.Name;
}
return value;
}
To be as follows:
public System.Collections.Generic.List<String> net_adapters()
{
List<String> values = new List<String>();
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
values.Add(nic.Name);
}
return values;
}
A more bizarre way (although this probably doesn't matter, since GetAllNetworkIntefaces is probably blocked until it has a complete list) will use IEnumerable<T>and yield return:
public IEnumerable<String> net_adapters()
{
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
yield return nic.Name;
}
yield break;
}
:
var obj = new Adapters();
var values = obj.net_adapters();
listBox1.ItemsSource = values;
( , .NET Framework)