C# 程序使用环境类获取 OS 页面文件的内存大小
环境类提供有关当前平台的信息并操作当前平台。它对于获取和设置各种与操作系统相关的信息很有用。我们可以使用它来检索命令行参数信息、退出代码信息、环境变量设置信息、调用堆栈信息的内容以及自上次系统启动以来的时间(以毫秒为单位)信息。在本文中,我们将讨论如何找到 OS Page 文件的内存大小。所以我们可以通过SystemPageSize属性找到 OS 页面文件的内存大小。此属性返回操作系统内存页中存在的字节数。
句法:
Environment.SystemPageSize
返回类型:此属性的返回类型是整数。
例子:
C#
// C# program to find the size of operating
// system's memory page. Using Environment Class
using System;
class GFG{
static public void Main()
{
// Declare a variable
int result;
// Now we find the memory size for OS Page file
// Using SystemPageSize property of Environment class
result = Environment.SystemPageSize;
// Display the result
Console.WriteLine("The memory size for OS page file is " + result);
}
}
C#
// C# program to find the size of operating
// system's memory page. Using Environment Class
using System;
class GFG{
static public void Main()
{
// Arithmetic operation
int Sum = 1 + 3;
Console.WriteLine("Sum:" + Sum);
// Declare a variable
int res;
// Now we find the memory size for OS Page file
// Using SystemPageSize property of Environment class
res = Environment.SystemPageSize;
// Display the result
Console.WriteLine("The memory size for OS page file is " + res);
}
}
输出:
The memory size for OS page file is 4096
示例 2:
C#
// C# program to find the size of operating
// system's memory page. Using Environment Class
using System;
class GFG{
static public void Main()
{
// Arithmetic operation
int Sum = 1 + 3;
Console.WriteLine("Sum:" + Sum);
// Declare a variable
int res;
// Now we find the memory size for OS Page file
// Using SystemPageSize property of Environment class
res = Environment.SystemPageSize;
// Display the result
Console.WriteLine("The memory size for OS page file is " + res);
}
}
输出:
Sum:4
The memory size for OS page file is 4096