平常工作中经常用到string.join()方法,在vs 2017用的运行时(System.Runtime, Version=4.2.0.0)中,共有九个(重载)方法。
// // 摘要: // Concatenates the members of a collection, using the specified separator between // each member. // // 参数: // separator: // The string to use as a separator.separator is included in the returned string // only if values has more than one element. // // values: // A collection that contains the objects to concatenate. // // 类型参数: // T: // The type of the members of values. // // 返回结果: // A string that consists of the members of values delimited by the separator string. // If values has no members, the method returns System.String.Empty. // // 异常: // T:System.ArgumentNullException: // values is null. public static String Join<T>(String separator, IEnumerable<T> values); // // 摘要: // Concatenates the members of a constructed System.Collections.Generic.IEnumerable`1 // collection of type System.String, using the specified separator between each // member. // // 参数: // separator: // The string to use as a separator.separator is included in the returned string // only if values has more than one element. // // values: // A collection that contains the strings to concatenate. // // 返回结果: // A string that consists of the members of values delimited by the separator string. // If values has no members, the method returns System.String.Empty. // // 异常: // T:System.ArgumentNullException: // values is null. public static String Join(String separator, IEnumerable<String> values); // // 摘要: // Concatenates the elements of an object array, using the specified separator between // each element. // // 参数: // separator: // The string to use as a separator. separator is included in the returned string // only if values has more than one element. // // values: // An array that contains the elements to concatenate. // // 返回结果: // A string that consists of the elements of values delimited by the separator string. // If values is an empty array, the method returns System.String.Empty. // // 异常: // T:System.ArgumentNullException: // values is null. public static String Join(String separator, params object[] values); // // 摘要: // Concatenates all the elements of a string array, using the specified separator // between each element. // // 参数: // separator: // The string to use as a separator. separator is included in the returned string // only if value has more than one element. // // value: // An array that contains the elements to concatenate. // // 返回结果: // A string that consists of the elements in value delimited by the separator string. // If value is an empty array, the method returns System.String.Empty. // // 异常: // T:System.ArgumentNullException: // value is null. public static String Join(String separator, params String[] value); // // 摘要: // Concatenates the specified elements of a string array, using the specified separator // between each element. // // 参数: // separator: // The string to use as a separator. separator is included in the returned string // only if value has more than one element. // // value: // An array that contains the elements to concatenate. // // startIndex: // The first element in value to use. // // count: // The number of elements of value to use. // // 返回结果: // A string that consists of the strings in value delimited by the separator string. // -or- System.String.Empty if count is zero, value has no elements, or separator // and all the elements of value are System.String.Empty. // // 异常: // T:System.ArgumentNullException: // value is null. // // T:System.ArgumentOutOfRangeException: // startIndex or count is less than 0. -or- startIndex plus count is greater than // the number of elements in value. // // T:System.OutOfMemoryException: // Out of memory. public static String Join(String separator, String[] value, int startIndex, int count); // // 参数: // separator: // // value: public static String Join(char separator, params String[] value); // // 参数: // separator: // // value: // // startIndex: // // count: public static String Join(char separator, String[] value, int startIndex, int count); // // 参数: // separator: // // values: public static String Join(char separator, params object[] values); // // 参数: // separator: // // values: // // 类型参数: // T: public static String Join<T>(char separator, IEnumerable<T> values);
所以平常写方法的时候,基本上都覆盖了。
常用方法:separator以“,”为例。
string.Join(',',string[]) //字符','分割,拼接字符串数组
string.Join(',',List<string>) //字符','分割,拼接字符串列表
string.Join(",",string[]) //字符串“,”分割,拼接字符数组
string.Join(",",List<string>) //字符串“,”分割,拼接字符数组
备注:vs2013中重载方法没有这么多,需注意。