国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#中List〈string〉和string[]數組之間的相互轉換

2020-01-24 03:37:58
字體:
來源:轉載
供稿:網友

1,從System.String[]轉到List<System.String>

System.String[] str={"str","string","abc"};

List<System.String> listS=new List<System.String>(str);

 

2, 從List<System.String>轉到System.String[]

List<System.String> listS=new List<System.String>();

listS.Add("str");

listS.Add("hello");

System.String[] str=listS.ToArray();

 

測試如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.String[] sA = { "str","string1","sting2","abc"};
            List<System.String> sL = new List<System.String>();
            for (System.Int32 i = 0; i < sA.Length;i++ )
            {
                Console.WriteLine("sA[{0}]={1}",i,sA[i]);
            }
            sL = new List<System.String>(sA);
            sL.Add("Hello!");
            foreach(System.String s in sL)
            {
                Console.WriteLine(s);
            }
            System.String[] nextString = sL.ToArray();
            Console.WriteLine("The Length of nextString is {0}",nextString.Length);
            Console.Read();
        }
    }
}

結果顯示:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 建阳市| 逊克县| 灵璧县| 浏阳市| 宜都市| 宁河县| 射洪县| 德令哈市| 靖远县| 五指山市| 秦皇岛市| 大悟县| 拉孜县| 历史| 卓尼县| 沂源县| 西丰县| 游戏| 龙井市| 汪清县| 三原县| 长泰县| 张家口市| 巫溪县| 定襄县| 康定县| 环江| 醴陵市| 罗田县| 广昌县| 宝坻区| 临洮县| 天祝| 金平| 江油市| 衡阳市| 陆良县| 平舆县| 拜泉县| 息烽县| 莱西市|