.NET 2.x Системная информация - как улучшить код? - C#
Формулировка задачи:
Проблема в том что выходит слишком много foreach, как всё это можно сократить?
string savePath = @"C:\Sys.txt";
using (FileStream file = new FileStream(savePath, FileMode.Append))
{
using (StreamWriter twf = new StreamWriter(file, Encoding.UTF8))
{
foreach (ManagementBaseObject avResult in avsearcher.Get())
{
pcAntivirus = "& " + (avResult.GetPropertyValue("displayName")).ToString();
pcAntivirus = (pcAntivirus.StartsWith("& ")) ? pcAntivirus.Substring(1) : pcAntivirus;
twf.WriteLine(" антивирус: " + pcAntivirus);
}
foreach (ManagementObject gr in gs.Get())
{
foreach (PropertyData pty in gr.Properties)
{
if (pty.Name == "Description")
{
pcGPU += pty.Value.ToString();
twf.WriteLine(" Видеоадаптер: " + pcGPU);
}
}
}
foreach (ManagementObject gob in sar.Get())
{
twf.WriteLine(" Модель компьютера: " + gob["Manufacturer"] + gob["Model"]);
}
Сильно сложно описал?)
...UP
Решение задачи: «.NET 2.x Системная информация - как улучшить код?»
textual
Листинг программы
pcAntivirus = "& " + (avResult.GetPropertyValue("displayName")).ToString();
pcAntivirus = (pcAntivirus.StartsWith("& ")) ? pcAntivirus.Substring(1) : pcAntivirus;