zoukankan      html  css  js  c++  java
  • 获取系统内存大小(C#)

    代码如下:

            /// <summary>
            
    /// 获取系统内存大小
            
    /// </summary>
            
    /// <returns>内存大小(单位M)</returns>
            private static int GetPhisicalMemory()
            {
                ManagementObjectSearcher searcher 
    = new ManagementObjectSearcher();   //用于查询一些如系统信息的管理对象 
                searcher.Query = new SelectQuery("Win32_PhysicalMemory """new string[] { "Capacity" });//设置查询条件 
                ManagementObjectCollection collection = searcher.Get();   //获取内存容量 
                ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator();

                
    long capacity = 0;
                
    while (em.MoveNext())
                {
                    ManagementBaseObject baseObj 
    = em.Current;
                    
    if (baseObj.Properties["Capacity"].Value != null)
                    {
                        
    try
                        {
                            capacity 
    += long.Parse(baseObj.Properties["Capacity"].Value.ToString());
                        }
                        
    catch
                        {
                            
    return 0;
                        }
                    }
                }
                
    return (int)(capacity / 1024 / 1024);
            } 
  • 相关阅读:
    python 正则表达式
    Python 集合
    Python 类的使用
    Python 分支、循环语句
    Python 基础之字典(dict)的用法
    Python 之字符串常用操作
    python tuple元组操作
    Python list的常用操作
    appium 二次切换webview后无法找到页面元素
    Locust API 文档
  • 原文地址:https://www.cnblogs.com/Aricc/p/1524675.html
Copyright © 2011-2022 走看看