If you are using .NET Core, the System.Diagnostics.PerformanceCounter is not an option. Try this instead:
System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
long ram = p.WorkingSet64;
Console.WriteLine($"RAM: {ram/1024/1024} MB");