SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 146 | Next

Scott Klein

"Professional LINQ"


In the following example, the ElementAtOrDefault operator returns the element at index 50,000 (there
are slightly fewer the 20,000 contacts):
DataContext context = new DataContext("Initial Catalog = AdventureWorks;Integrated
Security=sspi");
Table contact = context.GetTable();
var query = from c in contact
where c.FirstName.StartsWith("S")
select c.FirstName;
listBox1.Items.Add(query.ElementAtOrDefault(50000));
When this query is executed, it tries to return the value at the specified index; when it does not find an
element at that index, it returns a default value of 0.
First
As its name suggests, the First operator returns the first element in a collection. Here??™s an example that
queries the Contact table looking for all contacts whose first name begins with the letter S. The First
operator returns the first element from the resulting collection.
DataContext context = new DataContext("Initial Catalog = @@ta
AdventureWorks;Integrated Security=sspi");
Table contact = context.GetTable();
var query = from c in contact
where c.


Pages:
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
systemy parkingowe Gadżety pożyczki gotówkowe money expert wypożyczalnia samochodów Bydgoszcz kulturystyka