var start = 2222; var ps = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Select(e => e.Port).Where(e => e > start).OrderBy(e => e).ToList(); var port = ps.Take(ps.Count - 1).Where((e, i) => ps[i + 1] - e > 1).FirstOrDefault();
var start = 2222; var ps = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Select(e => e.Port).Where(e => e > start).OrderBy(e => e).ToList(); var port = ps.Take(ps.Count - 1).Where((e, i) => ps[i + 1] - e > 1).FirstOrDefault();