C#控制臺(tái)基礎(chǔ) List泛型集合與對(duì)應(yīng)的數(shù)組相互轉(zhuǎn)換實(shí)現(xiàn)代碼
更新時(shí)間:2016年12月06日 21:07:00 投稿:mdxy-dxy
這篇文章主要介紹了C#控制臺(tái)基礎(chǔ) List泛型集合與對(duì)應(yīng)的數(shù)組相互轉(zhuǎn)換實(shí)現(xiàn)代碼,需要的朋友可以參考下
核心代碼:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
List<int> list = new List<int>();
list.Add(1);//插入單個(gè)元素
list.AddRange(new int[] { 1, 2, 3, 4 });//插入一個(gè)集合
//集合轉(zhuǎn)為數(shù)組
int[] nums = list.ToArray();
foreach (var item in nums)
{
Console.WriteLine(item);
}
Console.WriteLine();
//數(shù)組轉(zhuǎn)為集合
int[] nums2 = new int[] { 22,33,44};
List<int> newList = nums2.ToList();
foreach (var item in newList)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
}
}
效果圖:

相關(guān)文章
使用C#實(shí)現(xiàn)將Word?轉(zhuǎn)文本存儲(chǔ)到數(shù)據(jù)庫(kù)并進(jìn)行管理
這篇文章主要為大家詳細(xì)介紹了如何使用C#實(shí)現(xiàn)將Word?轉(zhuǎn)文本存儲(chǔ)到數(shù)據(jù)庫(kù)并進(jìn)行管理,文中的示例代碼講解詳細(xì),需要的小伙伴可以參考一下2024-03-03
詳解C#中經(jīng)典內(nèi)存泄露場(chǎng)景的寫(xiě)法
內(nèi)存泄漏是指程序中的內(nèi)存分配無(wú)法正確釋放,導(dǎo)致程序持續(xù)占用內(nèi)存而不釋放,最終可能導(dǎo)致系統(tǒng)資源不足的問(wèn)題,下面我們就來(lái)看看C#中C#中經(jīng)典內(nèi)存泄露場(chǎng)景的寫(xiě)法以及如何避免吧2024-03-03
Unity編輯器預(yù)制體工具類(lèi)PrefabUtility常用函數(shù)和用法
這篇文章主要為大家介紹了Unity編輯器預(yù)制體工具類(lèi)PrefabUtility常用函數(shù)及用法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08

