標籤:isp ted element lex each 列表 lib version https
String.Join 方法
平常工作中經常用到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);
string.Join 重載方法詳解
所以平常寫方法的時候,基本上都覆蓋了。
常用方法:separator以“,”為例。
string.Join(‘,‘,string[]) //字元‘,‘分割,拼接字串數組
string.Join(‘,‘,List<string>) //字元‘,‘分割,拼接字串列表
string.Join(",",string[]) //字串“,”分割,拼接字元數組
string.Join(",",List<string>) //字串“,”分割,拼接字元數組
備忘:vs2013中重載方法沒有這麼多,需注意。
C# string.join