如果 Windows 版本小于 7 则退出

Exit if Windows version is less than 7

我该怎么做?我跟着this教程,所以我有这个方法:

if (getOSInfo() >= "7")
{
    MessageBox.Show("Your Microsoft Windows version isn't supported.\n\nPlease use Windows 7 or above to be able to use this program.");
    Application.Current.Shutdown();
}

报错:

Cannot apply operator >= to operands of type string and string

因为方法 getOSInfo return 字符串数据类型并且它包含 "98" , "ME" , "XP" 不能和 >= 运算符比较,可以改成下面的代码:

if(Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1)
{
    // whatever you want to do...
}

正如@nelek提到的,这是一篇关于操作系统版本的综合文章:

https://docs.microsoft.com/en-us/windows/desktop/SysInfo/operating-system-version