Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ChrisN - 06 Aug 2007 21:56 GMT
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
Alexey Smirnov - 07 Aug 2007 08:29 GMT
> 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
[quoted text clipped - 27 lines]
>
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.