Getting the total installed physical memory (RAM) in the system is made simple using the following code snippet.
You can get the System’s total Physical Memory (RAM) programmatically using C#.
1 – Add a reference to Microsoft.VisualBasic
in your project.
2 – Write the following code:
// will give you Total Physical RAM of your System in Bytes
ulong ram = new Microsoft.VisualBasic.Devices.ComputerInfo() .TotalPhysicalMemory;
You need to convert the value to get Kilobytes (divide by 1024), to get Megabytes (divide by 1024*1024), to get Gigabytes (divide by 1024*1024*1024) and so on.
ulong ram = (new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory) / (1024 * 1024);