Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add string values to a C# list?
To add string values to a list in C#, use the Add() method.
Firstly, declare a string list in C# −
List<string> list1 = new List<string>();
Now add string items −
myList.Add("Jack");
myList.Add("Ben");
myList.Add("Eon");
myList.Add("Tim");
Let us see the complete code −
Example
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);
}
}
}Advertisements