數組,集合分割函數,join()

來源:互聯網
上載者:User

標籤:列表   dex   collect   指定   bsp   com   readline   http   log   

join函數定義如下:

     //     串聯類型為 System.String 的 System.Collections.Generic.IEnumerable<T> 構造集合的成員,其中在每個成員之間使用指定的分隔字元。         public static string Join(string separator, IEnumerable<string> values);        //     串聯字串集合的成員,其中在每個成員之間使用指定的分隔字元。        public static string Join<T>(string separator, IEnumerable<T> values);        //     串聯對象數組的各個元素,其中在每個元素之間使用指定的分隔字元。        public static string Join(string separator, params object[] values);        //     串聯字串數組的所有元素,其中在每個元素之間使用指定的分隔字元。        public static string Join(string separator, params string[] value);        //     串聯字串數組的指定元素,其中在每個元素之間使用指定的分隔字元。        public static string Join(string separator, string[] value, int startIndex, int count);

比如,我們常用“ , "來把一個數組給串聯起來。

這裡展示一個執行個體,分別把一個數組和一個List集合給串聯起來。

 static void Main(string[] args)        {            string[] param = new string[] { "小紅", "小明", "小張", "小劉" };            string param1 = string.Join(",", param);            Console.WriteLine(param1);            List<string> list = new List<string>();            list.Add("列表1");            list.Add("列表2");            list.Add("列表3");            list.Add("列表4");            string param2 = string.Join(",", list);            Console.WriteLine(param2);            Console.ReadLine();        }

結果如下:

 

數組,集合分割函數,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.