Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C#의 일반 목록이란 무엇입니까?

<시간/>

Generic List는 C#의 제네릭 컬렉션입니다. 크기는 배열과 달리 목록을 사용하여 동적으로 늘릴 수 있습니다.

예를 들어 보겠습니다 -

목록을 먼저 설정했습니다 -

List<string> myList = new List<string>()

이제 목록에 요소를 추가하십시오 -

List<string> myList = new List<string>() {
   "mammals",
   "reptiles",
   "amphibians"
}

이제 속성을 사용하여 추가된 요소 수를 계산해 보겠습니다. -

예시

using System;
using System.Collections.Generic;

class Program {
   static void Main() {
      List<string> myList = new List() {
         "mammals",
         "reptiles",
         "amphibians"
      };
      Console.WriteLine(myList.Count);
   }
}