Revolt Revolt - 1 month ago 7
C# Question

Add item to existing Collection C#

I have Collection:

public class Test
{
public double Index { set; get; }
public double A { set; get; }
public double B { set; get; }
public double C { set; get; }
}
List<Test> test = new List<Test>();


I filled A and B with some random numbers. After that, I want add items C in collection. For example, what I trying:

foreach (Test t in test)
{
c = t.A + t.B;
test.Add(new Test {C = c }); <------
}


How can I add element C on same position like A and B? (Sorry for my english)

M B M B
Answer
foreach (Test t in test)
{
    t.C = t.A + t.B;
} 

just set the property to the equation

Comments