【问题标题】:C#: Is 64bit operating system cross platform (windows, unix, mac) Net 2.0C#:是64位操作系统跨平台(windows、unix、mac)Net 2.0
【发布时间】:2015-03-21 13:22:09
【问题描述】:

我想通过 C#,使用 NET 2.0 框架来确定我的操作系统是 32 位还是 64 位。

我不能使用Environment.Is64BitOperatingSystem,因为只在net4及以上有效。

Y 不能使用原生 dll windows 函数或注册表属性,因为这仅对 windows 有效。

有没有办法在 unix 和 mac 中检查这个?

【问题讨论】:

  • 您必须决定如何根据运行时环境进行检查。这意味着您将需要所有三个实现。
  • 是的,我有适用于 windows 的代码,但我找不到任何适用于 MAC OS X 和 Unix 的代码
  • @Yuval 我会看看的。
  • 是的,包括 Windows XP。
  • 你能检查那个链接吗? [如何使用.NET检测Windows 64位平台?][1] [1]:stackoverflow.com/questions/336633/…

标签: c# operating-system cross-platform


【解决方案1】:

最后,这适用于 Linux(Unix 和 Mac):

    static string GetLinuxArchitectureType()
    {
        Mono.Unix.Native.Utsname result;
        int res = Mono.Unix.Native.Syscall.uname(out result);

        if (res < 0)
            return "N/A";

        return result.machine;
    }

【讨论】:

  • 我说我已经有了这个windows的代码,很容易找到。我首先检查操作系统类型并在 unix 和 mac 上使用此功能
  • 要检查操作系统类型,你使用stackoverflow.com/a/9129523/2626313,如果是PlatformID.Unix,你会分支到这个函数?
  • 好吧,我切换以防万一 > PlatformID.WinCE(Unix、MAC 和 xBox,最后一个对我来说没有意义)
猜你喜欢
  • 2018-01-18
  • 1970-01-01
  • 2015-02-11
  • 1970-01-01
  • 2011-04-30
  • 2013-08-29
  • 2011-07-29
  • 2011-09-10
  • 1970-01-01
相关资源
最近更新 更多