码迷,mamicode.com
首页 > Windows程序 > 详细

C# string.join

时间:2018-06-03 14:22:49      阅读:359      评论:0      收藏:0      [点我收藏+]

标签: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

标签:isp   ted   element   lex   each   列表   lib   version   https   

原文地址:https://www.cnblogs.com/meng9527/p/9089615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!