When this query is run, a value of true is written to the list box because there is at least one contact
whose last name starts with the letter Z.
Contains
The Contains operator determines whether the returned collection contains a specific element. The return
value is a Boolean??”true if all the values satisfy the condition, false if they do not.
The following example queries the Contact table, returning a sequence of last names. The
Contains operator is applied to determine if the sequence contains an element of
??????Kleinerman.??™??™
DataContext context = new DataContext("Initial Catalog=AdventureWorks;Integrated
Security=sspi");
Table
contact = context.GetTable();
var query = from c in contact
select c.LastName;
listBox1.Items.Add(query.Contains("Kleinerman"));
Because the Contact table does contain at least one row whose last name is Kleinerman, the value of true
is returned and written to the list box.
You can also use a comparer as follows:
DataContext context = new DataContext("Initial Catalog=AdventureWorks;Integrated
Security=sspi");
Table contact = context.
Pages:
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169