C\#컨트롤 러 기초 List 범 형 집합 과 대응 하 는 그룹 상호 변환 실현 코드

1111 단어 C#List범용 집합
핵심 코드:

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);//       
      list.AddRange(new int[] { 1, 2, 3, 4 });//       
 
      //       
      int[] nums = list.ToArray(); 
      foreach (var item in nums) 
      { 
        Console.WriteLine(item); 
      } 
 
      Console.WriteLine(); 
 
      //       
      int[] nums2 = new int[] { 22,33,44}; 
      List<int> newList = nums2.ToList(); 
      foreach (var item in newList) 
      { 
        Console.WriteLine(item); 
      } 
 
      Console.ReadKey(); 
 
    } 
  } 
} 
효과 그림:

좋은 웹페이지 즐겨찾기