本文整理汇总了C#中System.Collections.Generic.List.Min方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.List.Min方法的具体用法?C# System.Collections.Generic.List.Min怎么用?C# System.Collections.Generic.List.Min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.List
的用法示例。
在下文中一共展示了System.Collections.Generic.List.Min方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NetSerial
internal void NetSerial()
{
try
{
searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT Name,NetConnectionID,Manufacturer,PNPDeviceID,MACAddress FROM Win32_NetworkAdapter");
ManagementObjectCollection net = searcher.Get();
//PHYISICALADAPTER NOT AVAILABLE IN XP
//string netCompStr = "xxx"; //to ensure no matchif not assigned
//var count = net.Cast<ManagementObject>().Where(s => s.GetPropertyValue("NetConnectionID") != null).Count(c => String.Compare((string)c.GetPropertyValue("NetConnectionID"), 0, "Local Area Connection", 0, 20) == 0); //prior to Windows 8
//if (count > 0)
// netCompStr = net.Cast<ManagementObject>().Where(s => s.GetPropertyValue("NetConnectionID") != null).Where(c => String.Compare((string)c.GetPropertyValue("NetConnectionID"), 0, "Local Area Connection", 0, 20) == 0).Min(s => (string)s.GetPropertyValue("NetConnectionID")); //should result in lowest numbered local area connection
//else if (count == 0)
//{
// var cnt = net.Cast<ManagementObject>().Where(s => s.GetPropertyValue("NetConnectionID") != null).Count(c => String.Compare((string)c.GetPropertyValue("NetConnectionID"), 0, "Ethernet", 0, 8) == 0); //Windows 8
// if (cnt > 0)
// netCompStr = net.Cast<ManagementObject>().Where(s => s.GetPropertyValue("NetConnectionID") != null).Where(c => String.Compare((string)c.GetPropertyValue("NetConnectionID"), 0, "Ethernet", 0, 8) == 0).Min(s => (string)s.GetPropertyValue("NetConnectionID")); //should result in lowest numbered local area connection
// //may need a wireless here in future for tablets
//}
//foreach (ManagementObject queryObj in net)
//{
// if ((string)queryObj.GetPropertyValue("NetConnectionID") == netCompStr)
// {
// sysData.compLAC_Name = (string)queryObj.GetPropertyValue("Name");
// sysData.compLAC_Mac = (string)queryObj.GetPropertyValue("MACAddress");
// break;
// }
//
//}
System.Collections.Generic.List<string> macAddrs = new System.Collections.Generic.List<string>();
System.Collections.Generic.List<string> names = new System.Collections.Generic.List<string>();
foreach (ManagementObject queryObj in net)
{
if (queryObj.GetPropertyValue("MACAddress") == null)
continue;
if (queryObj.GetPropertyValue("Manufacturer") == null)
continue;
else
{
if (queryObj.GetPropertyValue("Manufacturer").ToString().ToLower() == "microsoft")
continue;
}
Log.WritW("WMINetAdapter: MAC: " + queryObj.GetPropertyValue("MACAddress"));
string netConn = (string)queryObj.GetPropertyValue("NetConnectionID");
if (netConn != null && netConn.IndexOf("Wireless",StringComparison.CurrentCultureIgnoreCase) != -1)
continue;
string name = (string)queryObj.GetPropertyValue("Name");
if (name == null)
continue;
name = name.ToLower();
if (name.Contains("bluetooth") || name.Contains("wireless") || name.Contains("wifi") || name.Contains("mobile") || name.Contains("wlan") || name.Contains("802.11"))
continue;
if (queryObj.GetPropertyValue("PNPDeviceID").ToString().Contains("ROOT"))
continue;
macAddrs.Add(queryObj.GetPropertyValue("MACAddress").ToString());
names.Add(queryObj.GetPropertyValue("Name").ToString());
}
Log.WriteStr("MAC Address count : " + macAddrs.Count.ToString());
macAddress = macAddrs.Min();
string str = "";
if (macAddrs.Count > 1)
str = macAddrs.Count.ToString();
if (macAddrs.Count > 0)
{
sysData.compLAC_Name = names[macAddrs.IndexOf(macAddress)] + str;
sysData.compLAC_Mac = macAddress;
}
Log.WritW("NetAdapter Final: serial: " + sysData.compLAC_Mac + " NetAdapterName: " + sysData.compLAC_Name);
}
catch (ManagementException e)
{
MessageBox.Show("An Error occurred while querying Net Adapter Info WMI data: " + e.Message, "Tax-Aide Inventory Data Collection");
Log.WritW("An Error occurred while querying Network WMI data: " + e.Message);
Environment.Exit(0);
}
}