C#

test2 list클래스 예제

하이브 Hive 2021. 7. 23. 13:52
반응형

최종

using System;
using System.Collections.Generic;

namespace test2
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list1 = new List<int>(); //오른쪽을 왼쪽 list1 대입
            List<string> list2 = new List<string>();//list후 tap키 누르면 string 선택됨

            list1.Add(1); //비어있는 앞자리에 1이 들어간것임
            int[] x = { 2, 3, 4, 5 };
            list1.AddRange(x); //add는 하나씩 넣는 거 addrange는 통채로 넣는 것
            list1.Insert(1, 10);  //중간에 넣을 떄 insert

            list1.Remove(10); //item삭제
            list1.Remove(0); //index

            Console.WriteLine(list1.Count); //get은 읽기 쓰기 중 읽기 항목들의 개수를 알려줄것입니다. count라는 속성 


            /*
            foreach (var item in list1)  // foreach 치고 tap tap 하면 자동완성 collection를 list1으로 변경
            {
                Console.WriteLine(item);
            }
            */
        }
    }
}


반응형