How to Get Total Physical RAM in C#
By FoxLearn 1/8/2025 9:55:07 AM 194
Retrieving the total installed physical memory (RAM) on the system is straightforward.
You can easily access the system's total physical memory (RAM) programmatically using C# by adding a reference to Microsoft.VisualBasic in your project.
Next, retrieve the total physical RAM of your system in bytes.
ulong ram = (new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory) / (1024 * 1024);
You should convert the value as follows:
- To get Kilobytes, divide by 1024;
- To get Megabytes, divide by 1024 * 1024;
- To get Gigabytes, divide by 1024 * 1024 * 1024, and so on.
- Using the OrderBy and OrderByDescending in LINQ
- Querying with LINQ
- Optimizing Performance with Compiled Queries in LINQ
- MinBy() and MaxBy() Extension Methods in .NET
- SortBy, FilterBy, and CombineBy in NET 9
- Exploring Hybrid Caching in .NET 9.0
- Using Entity Framework with IDbContext in .NET 9.0
- Primitive types in C#