「C#」判断系统位数 64bit 32bit

- 姿势一 .net 4.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            bool type;
            type = Environment.Is64BitOperatingSystem; //.net 4.0 
            Console.WriteLine(type);
            Console.ReadKey();
        }
    }
}

- 姿势二 .net 2.0

编译的时候要选择any/cpu

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication12
{
    class Program
    {
        static void Main(string[] args)
        {
            if (IntPtr.Size == 8)
            {
                Console.Write("64 bit");//64 bit
                Console.ReadKey();
            }
            else if (IntPtr.Size == 4)
            {
                Console.Write("32bit");
                Console.ReadKey();
            }
            else
            {
                Console.Write("I dont known");
                Console.ReadKey();
            }
        }
    }
}

- 姿势三

这里写代码片

猜你喜欢

转载自blog.csdn.net/iverson1180/article/details/80991262