雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C#控制臺基礎(chǔ) List泛型集合與對應(yīng)的數(shù)組相互轉(zhuǎn)換實(shí)現(xiàn)代碼

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎ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(); 
 
    } 
  } 
} 

效果圖:

上一篇:C# 當(dāng)前系統(tǒng)時(shí)間獲取及時(shí)間格式詳解

欄    目:C#教程

下一篇:SQL+C#實(shí)現(xiàn)獲得當(dāng)前月的第一天與最后一天

本文標(biāo)題:C#控制臺基礎(chǔ) List泛型集合與對應(yīng)的數(shù)組相互轉(zhuǎn)換實(shí)現(xiàn)代碼

本文地址:http://www.jygsgssxh.com/a1/C_jiaocheng/6121.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有