问题
hi edit this code but get error " Cannt apply indexing with [] to an expression of type "view_process.managmentobject" for line 8
and what is formul for get 30% my memory?
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);
}
}
回答1:
Add a reference to Microsoft.VisualBasic.dll. Then getting total physical memory is as simple as this (yes, I tested it):
static ulong GetTotalMemoryInBytes()
{
return new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory;
}
来源:https://stackoverflow.com/questions/15790706/get-total-memory-ram-pc-in-c-sharp