C# string.join

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.