Search:

Custom Search
_________________________________________________________________

Friday, February 8, 2008

Simple Methods using Lists (c#).

This method steps over each element of the list and calculates the total (just an integer value located in the class Component).

private List<Component> list = new List<Component>();

public int total()

{

int total = 0;

foreach (Component c in this.List)

{

total = total + c.totalH();

}

return total;

}

Now, if you want to find something on that list but you don’t want to step over every single element of the list (to stop when the “something” was found) you need to add the break expression.

foreach (Component c in this.List)

{

if (c.id == 5)

{

List.Remove(c);

break;

}

}

No comments: