You can use the LINQ Union extension.
Note that you can combine any type of IEnumerable with this method (Array, IList, etc.), so you donโt have to worry about the Add method. You must understand that LINQ creates consistent results, so you need to use "ToList ()", "ToDictionary ()" or whatever if you want to manipulate the collection later.
var list = (IList<Student>) new [] { new Student {FirstName = "Jane"}, new Student {FirstName = "Bill"}, }; var allStudents = list.Union( new [] {new Student {FirstName = "Clancey"}}) .OrderBy(s => s.FirstName).ToList(); allStudents[0].FirstName = "Billy"; foreach (var s in allStudents) { Console.WriteLine("FirstName = {0}", s.FirstName); }
Output:
FirstName = Billy FirstName = Clancey FirstName = Jane
source share