tag:blogger.com,1999:blog-8259613.post6137710550110165679..comments2023-08-05T11:16:50.347+02:00Comments on Kristof Verbiest - Bite-size C#: Removing items from a collectionKristofhttp://www.blogger.com/profile/01727380410232817527noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-8259613.post-12017293693847868362010-05-11T11:49:20.142+02:002010-05-11T11:49:20.142+02:00i like thisi like thiswww.oracledba.inhttp:///www.oracledba.innoreply@blogger.comtag:blogger.com,1999:blog-8259613.post-9227481233092551842010-03-02T01:16:18.303+01:002010-03-02T01:16:18.303+01:00Sorry this is not about the thread, but I just wan...Sorry this is not about the thread, but I just wanted to thank you for such a useful and well written collection of "easily consumable" point of interest that I care about.<br /><br />Great work Kristof!jtomaskonoreply@blogger.comtag:blogger.com,1999:blog-8259613.post-79965032314826705902009-01-05T18:12:00.000+01:002009-01-05T18:12:00.000+01:00The first method is great to Remove Collection whi...The first method is great to Remove Collection which is in a Collection.<BR/><BR/>For example i have two Collections <BR/><BR/>List:Page Pages // Id,PageId,PageName<BR/><BR/>List:SecuredPage SecurePages // Id,PageId,RoleId<BR/><BR/>I want to remove the each Page object inside Pages collection where Pages[x].PageId == SecurePages[x].PageId<BR/><BR/>If you directly loop through Pages and SecurePages(nested) and remove the item x.PageId == y.PageId you get an error about "collection changed, it is cancelled"<BR/><BR/>so the first method is really a nice tactic.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8259613.post-23718454928868966622008-11-19T21:19:00.000+01:002008-11-19T21:19:00.000+01:00I'm sorry. Of course lambda expressions only work ...I'm sorry. Of course lambda expressions only work with C# 3.0. For C# 2.0 the syntax would be like this:<BR/><BR/>colors = colors.FindAll(delegate(string color) { return color != "green"; });Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8259613.post-88914777198369271842008-10-29T22:14:00.000+01:002008-10-29T22:14:00.000+01:00I like to add yet another alternative. The functio...I like to add yet another alternative. The functional approach: Here we don't alter the original collection, but create a complete new one.<BR/><BR/>This code shows a LINQ query and works with C# 3.0:<BR/>colors = (<BR/> from color in colors <BR/> where color != "green" <BR/> select color<BR/> ).ToList();<BR/><BR/>But even cleaner is it when we use the List{T}.FindAll method. This next example works with .NET 2.0 and C# 2.0.<BR/><BR/>colors = colors.FindAll(s => s != "green");Anonymousnoreply@blogger.com