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

use*_*890 1 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);
   }
Run Code Online (Sandbox Code Playgroud)

在这我得到错误; 要求.任何人都可以帮助我.

谢谢!

Ric*_*III 5

将您的代码更改为:

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

或者,甚至更短:

private int FindNumber(string sPar)
{
      return Convert.ToInt32(sPar.Substring(sPar.Length - 1));
}
Run Code Online (Sandbox Code Playgroud)