C#中List〈string〉和string[]數(shù)組之間的相互轉(zhuǎn)換
1,從System.String[]轉(zhuǎn)到List<System.String>
System.String[] str={"str","string","abc"};
List<System.String> listS=new List<System.String>(str);
2, 從List<System.String>轉(zhuǎn)到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();
}
}
}
結(jié)果顯示:
- asp.net(c#)網(wǎng)頁跳轉(zhuǎn)七種方法小結(jié)
- C#幾種截取字符串的方法小結(jié)
- C#中HttpWebRequest的用法詳解
- C# DataGridView添加新行的2個方法
- C# 一個WCF簡單實(shí)例
- c#處理3種json數(shù)據(jù)的實(shí)例
- c#實(shí)現(xiàn)16進(jìn)制和字符串之間轉(zhuǎn)換的代碼
- c#使用多線程的幾種方式示例詳解
- C#中WinForm程序退出方法技巧總結(jié)
- 關(guān)于C#泛型列表List<T>的基本用法總結(jié)
- C# 通過NI-VISA操作Tektronix TBS 2000B系列示波器的實(shí)現(xiàn)步驟
相關(guān)文章
C#中通過API實(shí)現(xiàn)的打印類 實(shí)例代碼
這篇文章介紹了,C#中通過API實(shí)現(xiàn)的打印類 實(shí)例代碼,有需要的朋友可以參考一下2013-08-08
C# Record構(gòu)造函數(shù)的行為更改詳解
C# 9 中的record類型是僅具有只讀屬性的輕量級、不可變數(shù)據(jù)類型(或輕量級類),下面這篇文章主要給大家介紹了關(guān)于C# Record構(gòu)造函數(shù)的行為更改的相關(guān)資料,需要的朋友可以參考下2021-08-08

