-4

嗨,编辑此代码,但出现错误“无法使用 [] 将索引应用于第 8 行的“view_process.managmentobject”类型的表达式

什么是获取 30% 记忆的公式?

private static void DisplayTotalRam()
    {
        string Query = "SELECT MaxCapacity FROM Win32_PhysicalMemoryArray";
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(Query);
        int amount = 0;
        foreach (ManagementObject memo in searcher.Get())
        {
            amount += Convert.ToInt32(Convert.ToInt64(memo["Capacity"]) / 1024 / 1024 / 1024);

        }
    }
4

1 回答 1

2

添加对 Microsoft.VisualBasic.dll 的引用。然后获得总物理内存就这么简单(是的,我测试过):

static ulong GetTotalMemoryInBytes()
{
    return new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory;
}
于 2013-04-03T14:53:19.157 回答