I have this linq method, how to get all the properties of a computer network card, and I do not want to use linq, can I help convert it and not use Linq?
public NetworkAdapter[] GetAll() { return (from adapter in NetworkInterface.GetAllNetworkInterfaces() from uniCast in adapter.GetIPProperties().UnicastAddresses where !System.Net.IPAddress.IsLoopback(uniCast.Address) && uniCast.Address.AddressFamily != AddressFamily.InterNetworkV6 let lastGatewayAddress = adapter.GetIPProperties().GatewayAddresses.LastOrDefault() select new NetworkAdapter() { string Name = adapter.Name, string ID = adapter.Id, string Description = adapter.Description, string IPAddress = uniCast.Address.ToString(), string NetworkInterfaceType = adapter.NetworkInterfaceType.ToString(), string Speed = adapter.Speed.ToString("#,##0"), string MacAddress = getMacAddress(adapter.GetPhysicalAddress().ToString()), string gatewayIpAddress = string.Join(" ", adapter.GetIPProperties().GatewayAddresses.Select(a => a.Address)) }).ToArray(); }
this is what i tried;
public void get() { NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in nics) { Description = adapter.Description; Name = adapter.Name; MacAddress = adapter.GetPhysicalAddress().ToString(); IPInterfaceProperties ips = adapter.GetIPProperties(); UnicastIPAddressInformationCollection uniCast = ips.UnicastAddresses; foreach (UnicastIPAddressInformation ipInfo in uniCast) { if (ipInfo.Address.AddressFamily != AddressFamily.InterNetworkV6) { } } } }
source share