这是我的课程,我想返回我的机器网络接口集合。我选择返回 IEnumerable,但我不知道该怎么做(我是新开发人员)。或者也许有击球手的方式来建立我的班级?
public class NetworkAdapter
{
string _name;
string _id;
string _description;
string _ipAddress;
string _gatewayIpAddress;
string _speed;
string _networkInterfaceType;
string _macAddress;
public IEnumerable<NetworkAdapter> getAdapterInfo()
{
foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces())
{
//fetch network configuration properties
var properties = adapter.GetIPProperties();
foreach (var uniCast in properties.UnicastAddresses)
{
//ignore loop-back addresses & IPv6 internet protocol family
if (!IPAddress.IsLoopback(uniCast.Address)
&& uniCast.Address.AddressFamily != AddressFamily.InterNetworkV6)
{
_name = adapter.Name;
_id = adapter.Id;
_description = adapter.Description;
_ipAddress = uniCast.Address.ToString();
_networkInterfaceType = adapter.NetworkInterfaceType.ToString();
_speed = adapter.Speed.ToString("#,##0");
_macAddress = adapter.GetPhysicalAddress().ToString();
var gatewayAddresses = adapter.GetIPProperties().GatewayAddresses;
foreach (var gatewayAddress in gatewayAddresses)
{
_gatewayIpAddress = gatewayAddress.Address.ToString();
}
}
}
}
yield return new NetworkAdapter att;
}
}