Developer’s Guide to Collections in Microsoft® .NET by Calvin Janes

Developer’s Guide to Collections in Microsoft® .NET by Calvin Janes

Author:Calvin Janes [Calvin Janes]
Language: eng
Format: epub
Tags: COMPUTERS / Programming / Microsoft Programming
ISBN: 9780735656833
Publisher: Microsoft Press
Published: 2011-09-15T16:00:00+00:00


Using a Lambda Expression with RemoveWhere

The following code removes all even values by using a lambda expression for the Predicate(T).

C#

HashSet<int> hs = new HashSet<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); hs.RemoveWhere(item => { return (item % 2) == 0; });

Visual Basic

Dim hs As New HashSet(Of Integer)(New Integer() {1, 2, 3, 4, 5, 6, 7, 8, 9}) hs.RemoveWhere(Function(x) x Mod 2 = 0)

The set contains [ 1, 3, 5, 7, 9 ] after the RemoveWhere call completes.

Performing Set Operations on a HashSet(T)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.