如何在 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);
      }
   }
}

更新日期:2020 年 6 月 21 日

7K+ 瀏覽量

開啟你的 事業

完成課程獲得認證

開始
廣告
© . All rights reserved.