I love the List<T> class in C#2.0+, but haven't really used it much beyond as a typed ArrayList. It's normally plenty.
But today I was building a dynamic CAML string and started doing a bunch of repetitive code like
Listwhen I realized there was a much simpler way:
clauses = new List (); string foo = GetFooClause(); if (!string.IsNullOrEmpty(foo)) clauses.Add(foo); string bar = GetBarClause(); if (!string.IsNullOrEmpty(bar)) clauses.Add(bar); //..
clauses = new List (); clauses.Add(GetFooClause()); clauses.Add(GetBarClause()); //... //remove all empty clauses clauses.RemoveAll(string.IsNullOrEmpty);