我是 linq 的新手,想用它来获取 iOS 设备的 IP 地址。我想知道是否有人看到这种方法有任何问题(基于这个How do I get the network interface and its right IPv4 address?)或者是否有更好/更紧凑/更干净的方法来做到这一点。
// get my IP
string ip = NetworkInterface.GetAllNetworkInterfaces()
.Where(x => x.Name.Equals("en0"))
.Select(n => n.GetIPProperties().UnicastAddresses)
.Where(x => x.First().Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
.Select(x => x.First().Address.ToString());