帮帮手修改个函数
代码如下,当表示层调用时就报错了,void无法隐式转换string.using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
public void codeNumber(string source, string num)
{
int n1 = source.Length;
int n2 = num.Length;
string str1 = source.Substring(n1 - n2, n2);
try
{ int str2 = Convert.ToInt32(str1);
int num2 = Convert.ToInt32(num);
int sum = str2 + num2-1;
int n3 = sum.ToString().Length;
if (n3 > n2)
{
str1 = source.Substring(n1 - n2 - 1, n2 + 1);
str2 = Convert.ToInt32(str1);
sum = str2 + num2-1;
}
string str4 = source.Substring(0, n1 - n2) + sum.ToString();
Console.WriteLine(str4);
}
catch
{
Console.WriteLine("输入有误");
}
}
static void Main(string[] args)
{
Program c = new Program();
c.codeNumber("AB00230001", "70000");
}
}
}