标题:帮帮手修改个函数
取消只看楼主
jm1ghpef
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-9-22
结帖率:83.33%
 问题点数:0 回复次数:0 
帮帮手修改个函数
代码如下,当表示层调用时就报错了,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");
         
        }
    }
}
搜索更多相关主题的帖子: 函数 
2009-10-25 12:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-289856-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.102899 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved