Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Please translate this C# LINQ query into VB for me !!!!!

Reply
Thread Tools

Please translate this C# LINQ query into VB for me !!!!!

 
 
ChrisN
Guest
Posts: n/a
 
      08-06-2007
Just learning LINQ by going through the MSDN 101 LINQ samples, which
are in C#. I'm a VB developer and my C# doesn't extend to lambda
functions yet!

I'm stuck on...

public void Linq5() {
string[] digits = { "zero", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine" };

var shortDigits = digits.Where((digit, index) => digit.Length <
index);

Console.WriteLine("Short digits:");
foreach (var d in shortDigits) {
Console.WriteLine("The word {0} is shorter than its value.",
d);
}
}

Grateful if someone could rewrite the lambda expression

var shortDigits = digits.Where((digit, index) => digit.Length <
index);

in VB for me. I just can't work it out.

Thanks,

ChrisN

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      08-07-2007
On Aug 6, 10:56 pm, ChrisN <(E-Mail Removed)> wrote:
> Just learning LINQ by going through the MSDN 101 LINQ samples, which
> are in C#. I'm a VB developer and my C# doesn't extend to lambda
> functions yet!
>
> I'm stuck on...
>
> public void Linq5() {
> string[] digits = { "zero", "one", "two", "three", "four", "five",
> "six", "seven", "eight", "nine" };
>
> var shortDigits = digits.Where((digit, index) => digit.Length <
> index);
>
> Console.WriteLine("Short digits:");
> foreach (var d in shortDigits) {
> Console.WriteLine("The word {0} is shorter than its value.",
> d);
> }
>
> }
>
> Grateful if someone could rewrite the lambda expression
>
> var shortDigits = digits.Where((digit, index) => digit.Length <
> index);
>
> in VB for me. I just can't work it out.
>
> Thanks,
>
> N


Chris, how does it related to this newsgroup?

If you want to do in LINQ, there is a forum for such questions, take a
look
http://forums.microsoft.com/MSDN/Sho...D=123&SiteID=1

Regarding WHERE operator in LINQ: it should be something similar to
the following code

Dim digits = From digit In digits _
Where digit(index) => digit.length < index

and if you want to move the code to .Net2 then it will be something
like this

Dim digits As String() = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"}

Dim shortDigits As New ArrayList()
Dim i As Integer

For i = 0 To digits.Length - 1
If i > digits(i).Length Then
shortDigits.Add(digits(i))
End If
Next

Console.WriteLine("Short digits:")
For Each d As String In shortDigits
Console.WriteLine("The word {0} is shorter than its value.", d)
Next

Hope this helps

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linq or not Linq George ASP .Net 4 11-05-2008 04:53 PM
using a ListBox with SelectionMode="Multiple" in a linq query Seb ASP .Net 0 05-12-2008 08:08 PM
HowTo? LINQ Query Table Name (Range Variable) Not Known Until Runtime Joey ASP .Net 1 04-23-2008 04:33 PM
SQL Query to Linq (Group By and Sum) Alex Sauceda ASP .Net 6 02-04-2008 10:26 PM
LINQ Query shapper ASP .Net 2 10-18-2007 02:59 PM



Advertisments