不确定如何做到这一点,猜测 C# LINQ 可能是可能的。所以我有一个对象:
public class NContainer {
public string _HostFqdn { get; set; }
public string _HostIp { get; set; }
public int _Severity { get; set; }
public string _Issue { get; set; }
public string _ProtoPort { get; set; } }
我给它一个如下列表:
List<NContainer> nList = new List<NContainer>();
nList.Add( new NContainer { _HostFqdn = "ab1.corp.com", _HostIp = "192.168.0.2", _Severity = 1, _Issue = "Check 1", _ProtoPort = "TCP_80" } );
nList.Add( new NContainer { _HostFqdn = "ab2.corp.com", _HostIp = "192.168.0.3", _Severity = 2, _Issue = "Check 2", _ProtoPort = "TCP_81" } );
nList.Add( new NContainer { _HostFqdn = "ab3.corp.com", _HostIp = "192.168.0.4", _Severity = 1, _Issue = "Check 2", _ProtoPort = "TCP_82" } );
nList.Add( new NContainer { _HostFqdn = "ab4.corp.com", _HostIp = "192.168.0.5", _Severity = 3, _Issue = "Check 1", _ProtoPort = "TCP_80" } );
nList.Add( new NContainer { _HostFqdn = "ab5.corp.com", _HostIp = "192.168.0.6", _Severity = 3, _Issue = "Check 5", _ProtoPort = "TCP_443" } );
nList.Add( new NContainer { _HostFqdn = "ab6.corp.com", _HostIp = "192.168.0.7", _Severity = 4, _Issue = "Check 1", _ProtoPort = "TCP_80" } );
我希望能够在上面的列表中运行 LINQ 查询(或类似查询),以便控制台输出采用以下格式:
Group By _Issue
Check 1
192.168.0.2 TCP_80 192.168.0.5 TCP_82 192.168.0.7 TCP_80
Check 2
192.168.0.3 TCP_81 192.168.0.4 TCP_82
Check 5
192.168.0.6 TCP_443
我可以使用类似于下面的代码显示 List 和 orderby 的内容,但不知道如何以上面的格式显示输出?
List<NContainer> arrList = new List<NContainer>();
List<NContainer> query = from NContainer vulns in arrList
orderby vulns._Issue
where vulns._Severity >= 1
select vulns;
foreach (var vuln in query)
{
Console.WriteLine("{0}", vuln._Issue, vuln._HostIp, vuln._ProtoPort);
}
精慕HU
千巷猫影
相关分类