在c#中获取总内存(ram)pc [英] get total memory (ram) pc in c#
本文介绍了在c#中获取总内存(ram)pc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,编辑此代码但出现错误无法将 [] 索引应用于第 8 行的view_process.managmentobject"类型的表达式
hi edit this code but get error " Cannt apply indexing with [] to an expression of type "view_process.managmentobject" for line 8
获得 30% 我的记忆的公式是什么?
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);
}
}
推荐答案
添加对 Microsoft.VisualBasic.dll 的引用.然后获得总物理内存就这么简单(是的,我测试过):
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;
}
这篇关于在c#中获取总内存(ram)pc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文