c# - 检索计算机上的 RAM 总量

标签 c# performancecounter

<分区>

Possible Duplicate:
C# - How do you get total amount of RAM the computer has?

以下将检索有多少 ram 可用:

PerformanceCounter ramCounter;
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
Console.WriteLine("Total RAM: " + ramCounter.NextValue().ToString() + " MB\n\n");

当然,我们必须使用 System.Diagnostics;类。

performancecounter 是否具有检索特定机器的 RAM 数量的功能?我不是在谈论已使用或未使用的 ram 数量。我说的是机器的 ram 数量。

最佳答案

这些信息已经可以直接在 .NET 框架中使用,您不妨使用它。项目 + 添加引用,选择 Microsoft.VisualBasic。

using System;

class Program {
    static void Main(string[] args) {
        Console.WriteLine("You have {0} bytes of RAM",
            new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory);
        Console.ReadLine();
    }
}

不,它不会将您的 C# 代码转换为 vb.net。

关于c# - 检索计算机上的 RAM 总量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8462539/

相关文章:

c# - Parallel.For 在大约 1370 次迭代后卡住,不知道为什么

c# - 从 C# Azure Function Apps 调用 PowerShell

c# - 从 LINQ to SQL 表达式的逻辑方法

c++ - 使用性能计数器获取正常运行时间的权限问题

windows - Windbg 故障转储中的性能计数器

profiling - Linux 内核中 Perf 事件子系统的性能开销

c# - 获取进程的 CPU 和内存使用情况的正确性能计数器是什么?

c# - 我是否正确使用了 "using"语句?

c# - Microsoft.Diagnostics 与 Microsoft.Diagnostics.EventFlow 中的性能计数器

c# - 尝试播种数据库时出现 EF 异常