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

C# 목록에 정수 값을 추가하는 방법은 무엇입니까?

<시간/>

C#의 목록에 정수 값을 추가하려면 Add() 메서드를 사용하세요.

첫째, C#에서 정수 목록을 선언하십시오 -

List<int> list1 = new List<int>();

이제 정수 값을 추가하십시오 -

list1.Add(900);
list1.Add(400);
list1.Add(300);

전체 코드를 보자 -

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Demo {
   public class Program {
      public static void Main(String[] args) {
         List<int> list1 = new List<int>();
         list1.Add(900);
         list1.Add(400);
         list1.Add(300);
         Console.WriteLine(list1.Count);
      }
   }
}