如何在 C# 列表中添加字符串值?
若要在 C# 列表中添加字符串,请使用 Add() 方法。
首先,在 C# 中声明一个字符串列表 −
List<string> list1 = new List<string>();
现在添加字符串项 −
myList.Add("Jack");
myList.Add("Ben");
myList.Add("Eon");
myList.Add("Tim");我们看看完整的代码 −
示例
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<string> myList = new List<string>();
myList.Add("Jack");
myList.Add("Ben");
myList.Add("Eon");
myList.Add("Tim");
Console.WriteLine(myList.Count);
}
}
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP