可能有更好的方法来做到这一点,但这有效: 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" }); IEnumerable<NContainer> query = from NContainer vulns in nList orderby vulns._Issue where vulns._Severity >= 1 select vulns; Console.WriteLine("Group by _Issue"); var prevIssue = ""; bool first = true; foreach (var vuln in query) { if (prevIssue != vuln._Issue) { if (first) first = false; else Console.WriteLine("\n"); Console.WriteLine("\t{0}", vuln._Issue); Console.Write("\t"); prevIssue = vuln._Issue; } }基本上使用 Console.Write 而不是 WriteLine 以便您可以循环并将特定信息的所有 IP 信息附加到同一行。其余的只是格式化。在一个示例汽车游戏中,我希望能够让汽车在屏幕内移动,并且我希望它被边缘“绑定”。但是,它会不断剪辑并超出屏幕范围。我把图片框做成正方形,并使用汽车图片的尺寸,它在图片框中居中)作为代码模型的基础。图片框为 100x100,汽车图片(侧向时)大约为 50x100。例如,如果汽车在屏幕边缘侧向行驶,我会将图片框的 Y 位置设为 -25。但是,我觉得这太不方便了,因为我可能需要更改汽车的图片。这段代码工作得很好,但我觉得它太长了,太不方便了。
1 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
如果代码有效,那么,它可以明确地总结为:
int verticalDirection = Convert.ToInt32(iDirection == CarDirection.UP || iDirection == CarDirection.DOWN);
int horizontalDirection = Convert.ToInt32(iDirection == CarDirection.LEFT || iDirection == CarDirection.RIGHT);
if (pNewLoc.X <= 0)
{
pNewLoc.X = -25 * verticalDirection;
}
else
{
pNewLoc.X = iX + 25 * verticalDirection;
}
if (pNewLoc.Y <= 0)
{
pNewLoc.Y = -25 * horizontalDirection;
}
else
{
pNewLoc.Y = iY + 25 * horizontalDirection;
}
如果您更改图片的大小,那么您不必使用类似的常量,25而是声明一个取决于汽车图片大小的变量。
- 1 回答
- 0 关注
- 129 浏览
添加回答
举报
0/150
提交
取消
