Select 方法有四个重载方法,都是string类型的,如下
Select(string s1)
Select(string s1, string s2)
Select(string s1, string s2, string s3)
Select(string s1, string s2, string s3, string s4)我想增加下面一个方法,来根据参数的多少来决定重载上面的参数
Select(string[] args) 除了if和case一个一个判断还有其他简单方法吗?

解决方案 »

  1.   

    除了if来判断.length,我也想知道还有没有什么好点的方法
      

  2.   

    好像有个parms参数决定参数多少的,忘了.
      

  3.   

    http://www.cnblogs.com/maplye/archive/2006/07/07/445451.html
      

  4.   

    没必要这样做,因为系统会根据你方法的参数进行自动匹配的,没必要决定调用哪个方法。
    如果你这个方法的参数不定的话,建议这样写:using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Text;
    namespace JustTry
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine(Select("1", "2"));
                Console.WriteLine(Select("1", "2", "3"));
                Console.WriteLine(Select("1", "2", "3", "4"));
                Console.ReadLine();
            }        public static string Select(params string[] str) 
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < str.Length; i++) 
                {
                    sb.Append(str[i]);
                }
                return sb.ToString();
            }
        }
    }
      

  5.   

    用string Select(params string[] str) 一个函数就可以了经典的string.Format() 函数就是这种格式