creating an iterator that will give you the letters "a" to "z" as you enumerate it:
Dim letters(0 To 25) As Char
For i As Int32 = 0 To 25
letters(i) = ChrW(&H61 + i)
Next
By Using LINQDim letters = From i In Enumerable.Range(0, 26) _
Select ChrW(&H61 + i)
To read from a stream line-by-line,
search for a substring, and return the first couple of matches.strLine = myStreamReader.ReadLine
Do While strLine IsNot Nothing
If strLine.Contains(value) Then
count += 1
resultList.Add(strLine)
If count >= 3 Then Exit Do
End If
strLine = myStreamReader.ReadLine
Loop
Unfortunately, StreamReader doesn't have an
iterator that returns each line. Without something that is enumerable,
you can't form the basis of a LINQ query, so you're forced to write
your query imperatively. That's not as bad as it might first sound;
Building the query into the imperative procedural block does work,
although it's kind of on the ugly side.
If you have an extension method named Lines that
returns an IEnumerable with each item a line, then you can create a
query like this:Dim result = From line In myStreamReader.Lines _
Where line.Contains(value) _
Take 3
Wednesday, April 29, 2009
Some Simple LINQ Examples for existing examples
Here are some simple examples to understand better to LINQ
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment