본문 바로가기
공부,일/C#

List class

by fromnothing1 2021. 6. 3.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace _210603_008
{
    class Program
    {
        static void Main(string[] args)
        {
            // list 선언과 동시에 초기화 

            List<int> list = new List<int>() { 52, 273, 34, 64 };

            Console.WriteLine("====================");
            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("====================");
            list[list.IndexOf(34)] = 100; //52, 273, 100, 64 // 변경

            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("====================");

            list.Insert(1,500); // 52,500,273,100,64   삽입 

            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("list.Count : "+list.Count);
            Console.WriteLine("====================");
            
            list.RemoveAt(0);  // 500,273,100,64   삭제
            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("list.Count : " + list.Count);
            Console.WriteLine("====================");

        }
            static void Main1(string[] args)
        {
            //리스트 클래스 동적인 배열 할당을 위해서 사용한다.

            List<int> list = new List<int>();
            Console.WriteLine("list.Count: " + list.Count);
            list.Add(111);
            list.Add(222);
            list.Add(333);
            list.Add(444);
            Console.WriteLine("list.Count: " + list.Count);
            Console.WriteLine("");


            list[0] = 10000; // 배열처럼 접근 가능 
            Console.WriteLine("list.IndexOf(333) : "+list.IndexOf(333)); // 위치 찾기 


            Console.WriteLine("\nlist 요서 출력");
            foreach (var temp in list)
            {

                Console.WriteLine(temp);

            }



        }
    }
}

'공부,일 > C#' 카테고리의 다른 글

210604  (0) 2021.06.04
210603_2  (0) 2021.06.03
210602  (0) 2021.06.02
210525_2  (0) 2021.05.25
210525  (0) 2021.05.25

댓글