将FileVersionInfo GetVersionInfo与double进行比较 [英] Compare FileVersionInfo GetVersionInfo to a double

查看:78
本文介绍了将FileVersionInfo GetVersionInfo与double进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我无法将FileVersionInfo.GetVersionInfo数转换为double。我需要将它与一个数字进行比较,以提醒用户第三方程序已过期。



这是我到目前为止的内容:



FileVersionInfo psVersionInfo = FileVersionInfo.GetVersionInfo(process);

//这将获得该程序的版本。



我已经尝试过Convert.ToDouble(psVersionInfo)并且这不起作用。版本号的格式为6.6.54。



有人能说清楚我错过了什么吗?



谢谢大家!

Hi everyone!

I am having trouble converting the FileVersionInfo.GetVersionInfo number to a double. I need to compare it to a number to alert the user that the 3rd party program is out of date.

Here is what I have so far:

FileVersionInfo psVersionInfo = FileVersionInfo.GetVersionInfo(process);
// This will get the version of the program.

I''ve tried Convert.ToDouble(psVersionInfo) and that doesn''t work. The version number is in the form of "6.6.54".

Can someone shed some light as to what I''m missing?

Thanks everyone!

推荐答案

看看Darren Kopp的回答,这里...... http://stackoverflow.com/questions/30494/compare-version-identifiers [ ^ ]



'' g''
Have a look at Darren Kopp''s answer, here ... http://stackoverflow.com/questions/30494/compare-version-identifiers[^]

''g''


更好的转换不是双倍,而是转换为DWORD或ULONGLONG(在.NET中uint和ulong)。

并将高版本部分设置为高位顺序,所以你只能比较这两个数字。

在.NET中看起来会是:

Better converting not to double but to DWORD or ULONGLONG (in .NET it uint and ulong).
And make high version part to be at high bit order so you can compare that 2 numbers only.
In .NET it will looks:
public uint GetVersion(string _version)
{
    uint uiVersion = 0;
    string[] aVersion = _version.Split('.');
    for (int i = 0; i < aVersion.Length; i++)
    {
        uiVersion += (uint.Parse(aVersion[i]) << (8 * (aVersion.Length - i - 1)));
    }
    return uiVersion;
}



用法:


And the usage:

uint uiVersion1 = GetVersion("6.2.54");
uint uiVersion2 = GetVersion("6.2.52");
if (uiVersion1 > uiVersion2)
{
    // First version higher
}
if (uiVersion1 < uiVersion2)
{
    // Second version higher
}
if (uiVersion1 == uiVersion2)
{
    // Versions are equals
}



问候,

Maxim。


Regards,
Maxim.


据我所知,FileVersionInfo无法简单地转换为double。 ToString()方法将返回不正确的格式。尝试使用Double.Parse(6.6.54)解析它将抛出一个异常,这基本上就是Convert.ToDouble()将尝试做的事情。
As far as I am aware a FileVersionInfo cannot be converted to a double that simply. The ToString() method will return an incorrect format. Trying to parse it using Double.Parse("6.6.54") will throw an exception, which is basically what Convert.ToDouble() will try and do.


这篇关于将FileVersionInfo GetVersionInfo与double进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆