give me an exemple with List
Loading
give me an exemple with List
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Cynthia SathuragiriPosted Sep 2, 2026, 4:59 AM
Here’s a simple example of using
Listin C#. AListcan be used to store multiple text values, such as student names.For example:
In this example, the list stores three student names. The
foreachloop goes through each name and prints it. I thinkListis useful because it makes it easy to store and work with a collection of strings.Sangeetha SPosted Sep 1, 2026, 10:42 AM
List lines = new List
{
"Line1",
"Line2",
"Line3"
};
foreach (string line in lines)
{
Console.WriteLine($"{line}");
}
Snesh PrajapatiPosted Aug 17, 2026, 4:40 AM
Listin C# is a generic collection used to store multiple objects of the same type. T means "Type" and acts as a placeholder. Once you specify the type, the List only accepts that type. In your case you are specifying ListTbecomesstring.If you write List numbers = new List(); then
Tbecomesint.Rajanikant HawaldarPosted Aug 9, 2026, 5:07 PM
https://www.c-sharpcorner.com/article/c-sharp-list/
Sudarshan HajarePosted Aug 8, 2026, 2:26 AM
Output:
You can also create the list directly:
Then, for example:
List means a list that contains only strings.