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 148 | Next

Scott Klein

"Professional LINQ"

FirstName;
listBox1.Items.Add(query.Last());
You can also add specific criteria when using this operator. For instance, the following returns the last
element that satisfies a specific condition, the first name whose length is less than 5:
listBox1.Items.Add(query.Last(name => name.Length < 5));
FirstOrDefault
The FirstOrDefault operator returns the first element from a collection or, if no element is found, a
default value. The following example queries the Contact table looking for all contacts whose first name
begins with the letters ZZ, and the FirstOrDefault operator returns the first element from the returned
collection. If the element is not found, a default value is returned. The default value is defined as the first
element that is found that meets the query condition(s).
DataContext context = new DataContext("Initial Catalog=AdventureWorks;Integrated
Security=sspi");
Table contact = context.GetTable();
var query = from c in contact
where c.FirstName.StartsWith("ZZ")
select c.FirstName;
listBox1.Items.


Pages:
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6