using System.Collections.Generic;
public static void Main()
var colorPallete = new string[]
var list = new List<MyModel>()
new MyModel() { ID = 1, Name = "model1", Class = "A", },
new MyModel() { ID = 1, Name = "model11", Class = "AA", },
new MyModel() { ID = 2, Name = "model2", Class = "B", },
new MyModel() { ID = 3, Name = "model3", Class = "C", },
new MyModel() { ID = 4, Name = "model4", Class = "D", },
new MyModel() { ID = 5, Name = "model5", Class = "E", },
list.ForEach(x => x.Color = colorPallete.ElementAtOrDefault(x.ID - 1));
list.ForEach(x => Console.WriteLine(x));
Console.WriteLine("-----------------------------------");
list.ForEach(x => x.Color = colorPallete.ElementAtOrDefault(x.ID - 1) ?? "DefaultColor");
list.ForEach(x => Console.WriteLine(x));
Console.WriteLine("-----------------------------------");
list.ForEach(x => x.Color = colorPallete.ElementAtOrDefault((x.ID - 1) % colorPallete.Length));
list.ForEach(x => Console.WriteLine(x));
public int ID { get; set; }
public string Class { get; set; }
public string Name { get; set; }
public string Color { get; set; }
public override string ToString() {
return string.Format("ID={0};Color={1}", ID, Color);