locked
Help convert C# Linq to VB .Net Linq RRS feed

  • Question

  • User-284642143 posted

    A little weak with C# and Linq so wondering if someone could give me a hand and convert this line of code to VB .Net

    from c in credentials
    select c <= 0x7f ? (byte)c : (byte)'?')


    0x7f is an ascii character but not sure about the ?

    Im confused after select c not sure if this should be a function or not. Any help is appreciated

    Thanks

    Wednesday, December 18, 2013 1:49 PM

Answers

  • User281315223 posted

    You would likely need to use something like this as Visual Basic uses the '&HE' when referencing hex values : 

    Dim q = From c In credentials _
            Select If(c <= &HE7f, Convert.ToByte(c), Convert.ToByte("?"C)

    In Visual Basic, the If() statement is going to be equivalent to C#'s ternary '?' operator.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 18, 2013 4:27 PM

All replies

  • User2128776521 posted

    from c in credentials
    select c <= 0x7f ? (byte)c : (byte)'?')

    It seems to me that code does not compile in C# at all, without a lot of work.

    So, that makes it VERY hard to answer your question directly and accurately.

    That said, the following links may help you along the way.

    I am sorry that I cannot help more.

    101 Linq Samples In Cs...

    http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b

    101 Linq Samples In Vb...

    http://msdn.microsoft.com/en-us/vstudio/bb688088.aspx

    Free Online Code Converter...

    http://www.developerfusion.com/tools/

    HTH.

    Thanks.

    -- Mark Kamoski

    Wednesday, December 18, 2013 3:07 PM
  • User281315223 posted

    You would likely need to use something like this as Visual Basic uses the '&HE' when referencing hex values : 

    Dim q = From c In credentials _
            Select If(c <= &HE7f, Convert.ToByte(c), Convert.ToByte("?"C)

    In Visual Basic, the If() statement is going to be equivalent to C#'s ternary '?' operator.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 18, 2013 4:27 PM