以下是保存系统信息的示例代码:
使用 MDF 文件保存系统信息:
using System.IO;
public class SystemInfo
{
    public string OSVersion { get; set; }
    public string Processor { get; set; }
    public int Memory { get; set; }
}
public class SystemInfoManager
{
    public void SaveSystemInfo(SystemInfo systemInfo)
    {
        string fileName = "SystemInfo.mdf";
        using (StreamWriter file = new StreamWriter(fileName))
        {
            file.WriteLine($"OS Version: {systemInfo.OSVersion}");
            file.WriteLine($"Processor: {systemInfo.Processor}");
            file.WriteLine($"Memory: {systemInfo.Memory} GB");
        }
    }
}
// Example usage
SystemInfo systemInfo = new SystemInfo
{
    OSVersion = "Windows 10",
    Processor = "Intel Core i7",
    Memory = 16
};
SystemInfoManager manager = new SystemInfoManager();
manager.SaveSystemInfo(systemInfo);
使用 app.config 文件保存系统信息:
using System.Configuration;
public class SystemInfo
{
    public string OSVersion { get; set; }
    public string Processor { get; set; }
    public int Memory { get; set; }
}
public class SystemInfoManager
{
    public void SaveSystemInfo(SystemInfo systemInfo)
    {
        Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        config.AppSettings.Settings["OSVersion"].Value = systemInfo.OSVersion;
        config.AppSettings.Settings["Processor"].Value = systemInfo.Processor;
        config.AppSettings.Settings["Memory"].Value = systemInfo.Memory.ToString();
        config.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection("appSettings");
    }
}
// Example usage
SystemInfo systemInfo = new SystemInfo
{
    OSVersion = "Windows 10",
    Processor = "Intel Core i7",
    Memory = 16
};
SystemInfoManager manager = new SystemInfoManager();
manager.SaveSystemInfo(systemInfo);
以上代码示例分别使用 MDF 文件和 app.config 文件保存系统信息。您可以根据需要选择其中一种方法进行保存。
                    上一篇:保存熊猫相关矩阵而不是显示它
                
下一篇:保存修改后的用户数组