memory - How to display ram type in output using c#? -
i trying display size , type of ram in project. using windows 7 32 bit system. success in printing size of ram using
ulong mem = ulong.parse(ci.totalphysicalmemory.tostring()); console.writeline("total physical memory:{0}",mem/(1024*1024) + " mb");
but cannot display type of ram using :
public static string getmemorytype(int memorytype) { switch (memorytype) { case 20: return "ddr"; break; case 21: return "ddr-2"; break; default: if (memorytype == 0 || memorytype > 22) return "ddr-3"; else return "other"; break; } }
please me solve this.
simple snippet
add namespaces manually by
right-click references -->.net---> on right , manually add system.management --->add
using system.management; using system.management.instrumentation;
and code
public string ram_type() { int type=0; var searcher = new managementobjectsearcher("select * win32_physicalmemory"); foreach (managementobject obj in searcher.get()) { type = int32.parse(obj.getpropertyvalue("memorytype").tostring()); } switch (type) { case 20: return "ddr"; break; case 21: return "ddr-2"; break; case 17: return "sdram"; break; default: if (type == 0 || type > 22) return "ddr-3"; else return "unknown"; } }
Comments
Post a Comment