c# - 在 C# 中使用小数进行转换

标签 c#

private int FindNumber(string sPar)
   {
      // Get the last number
      int len = sPar.Length;
      string s = sPar.Substring(len-1);
      return new (int)Decimal(s);
   }

在这里我得到了错误;必需的 。任何人都可以帮我解决这个问题。

谢谢!

最佳答案

将您的代码更改为:

private int FindNumber(string sPar)
{
      int len = sPar.Length;
      string s = sPar.Substring(len - 1);
      return Convert.ToInt32(s);
}

或者,更短:

private int FindNumber(string sPar)
{
      return Convert.ToInt32(sPar.Substring(sPar.Length - 1));
}

关于c# - 在 C# 中使用小数进行转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3967717/

相关文章:

c# - 使用 NetTopologySuite TransformGeometry 时出错

c# - 将一个值与排序字典中的下一个值进行比较

c# - 在C#中将字符串解析为 "year-month-day"格式

c# - 如何从选择查询中计算重复记录

c# - WPF DataGrid 和多线程

c# - 有没有简单的方法来检查任何类实例的修改?

c# - 不需要的姓氏排序,尽管没有命令

c# - c#中两位小数的数字分组

c# - 是否可以通过 Azure 中运行的 Web API 对 Azure 外部的应用程序进行 HTTP 调用?

c# - `Type.GetProperties` 属性顺序