Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多点小数的C#.NET类型?_C#_Asp.net_.net_Type Conversion_.net 4.5 - Fatal编程技术网

多点小数的C#.NET类型?

多点小数的C#.NET类型?,c#,asp.net,.net,type-conversion,.net-4.5,C#,Asp.net,.net,Type Conversion,.net 4.5,我遇到了一个我似乎找不到任何答案的问题。我有一个格式为“5.2.3”的数字作为字符串,为了能够使用C#中的大于运算符和小于运算符,我应该将其转换为什么格式?我尝试了以下错误: Decimal version = Decimal.Parse(strVersion); if (version < Decimal.Parse("5.2.4")) { // Do something } Decimal version=Decimal.Parse(strrvision); if(版本0)

我遇到了一个我似乎找不到任何答案的问题。我有一个格式为“5.2.3”的数字作为字符串,为了能够使用C#中的大于运算符和小于运算符,我应该将其转换为什么格式?我尝试了以下错误:

Decimal version = Decimal.Parse(strVersion);
if (version < Decimal.Parse("5.2.4"))
{
     // Do something
}
Decimal version=Decimal.Parse(strrvision);
if(版本

基本上这个数字是十进制类型,它给了我一个错误“无效格式异常”?

我想你想比较一下版本

你可以用它

请尝试下面的示例代码

string v1=“1.23.56.1487”;
字符串v2=“1.24.55.487”;
变量版本1=新版本(v1);
变量版本2=新版本(v2);
var结果=版本1。与(版本2)相比;
如果(结果>0)
Console.WriteLine(“版本1更大”);
否则如果(结果<0)
Console.WriteLine(“版本2更大”);
其他的
Console.WriteLine(“版本相同”);
返回;
你看过吗?您的变量名似乎表明您正在查看版本号,并且该类提供了比较运算符。

使用版本

string n1 = "5.2.4";
string n2 = "5.3.4";

Version v1 = new Version(n1);
Version v2 = new Version(n2);

int result = v1.CompareTo(v2);

if (result > 0)
{
    //greater than v1
}
else if (result < 0)
{
    //2 is greater
}
else
{
    //they are equal
}
string n1=“5.2.4”;
字符串n2=“5.3.4”;
版本v1=新版本(n1);
版本v2=新版本(n2);
int结果=v1。与(v2)相比;
如果(结果>0)
{
//大于v1
}
否则如果(结果<0)
{
//2更大
}
其他的
{
//他们是平等的
}

这不是一个有效的数字。您打算将该数字存储为什么?这是应用程序的版本代码,我需要检查该版本是否低于我在“如果”声明中指定的版本?然后参见下面的答案。akho divas ahiya j padiyo hoy che?
string n1 = "5.2.4";
string n2 = "5.3.4";

Version v1 = new Version(n1);
Version v2 = new Version(n2);

int result = v1.CompareTo(v2);

if (result > 0)
{
    //greater than v1
}
else if (result < 0)
{
    //2 is greater
}
else
{
    //they are equal
}