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

Discussion in 'ASP .Net' started by ChrisN, Aug 6, 2007.

  1. ChrisN

    ChrisN Guest

    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
     
    ChrisN, Aug 6, 2007
    #1
    1. Advertisements

  2. On Aug 6, 10:56 pm, ChrisN <> 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/ShowForum.aspx?ForumID=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
     
    Alexey Smirnov, Aug 7, 2007
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shapper

    LINQ Query

    shapper, Oct 17, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    395
    sloan
    Oct 18, 2007
  2. Alex Sauceda

    SQL Query to Linq (Group By and Sum)

    Alex Sauceda, Feb 4, 2008, in forum: ASP .Net
    Replies:
    6
    Views:
    41,399
    Alex Sauceda
    Feb 4, 2008
  3. Joey
    Replies:
    1
    Views:
    756
    bruce barker
    Apr 23, 2008
  4. Seb
    Replies:
    0
    Views:
    608
  5. George

    Linq or not Linq

    George, Nov 4, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    429
    Mike Gleason jr Couturier
    Nov 5, 2008
Loading...

Share This Page