xxxxxxxxxx
//Declaring that its a list
List<string> test = new List<string>();
test.Add("Hello")
xxxxxxxxxx
using System;
using System.Collections.Generic;
namespace add_list
{
static void Main(string[] args)
{
List<string> first = new List<string> { "do", "rey", "me" };
List<string> second = new List<string> { "fa", "so", "la", "te" };
first.AddRange(second);
foreach(var e in first)
{
Console.WriteLine(e);
}
}
}
}
xxxxxxxxxx
Add List C# Simplified
var data = new List<TransactionModel>
{
new TransactionModel { ID = 1, Name = "Name 1" },
new TransactionModel { ID = 2, Name = "Name 2" }
};
xxxxxxxxxx
List<string> initialList = new List<string>();
// Put whatever you want in the initial list
List<string> listToAdd = new List<string>();
// Put whatever you want in the second list
initialList.AddRange(listToAdd);
xxxxxxxxxx
List<int> list1 = new List<int>() { 1, 2, 3 };
List<int> list2 = new List<int>() { 4, 5, 6 };
// Adding list2 elements to list1
list1.AddRange(list2);
// Output the combined list
foreach (int number in list1)
{
Console.WriteLine(number);
}