0

I am trying to convert this code

public static byte[] NewLine(this byte[] bytes, int feeds = 1)
    {
      return bytes.AddBytes(((IEnumerable<byte>) new byte[feeds]).Select<byte, byte>((Func<byte, byte>) (x => (byte) 10)).ToArray<byte>());
    }

online converters produce this

<System.Runtime.CompilerServices.Extension> _
    Public Function NewLine(ByVal bytes() As Byte, Optional ByVal feeds As Integer = 1) As Byte()
      Return bytes.AddBytes((DirectCast(New Byte(feeds - 1){}, IEnumerable(Of Byte))).Select(Of Byte, Byte)CType(Function(x) CByte(10), Func(Of Byte, Byte)).ToArray())
    End Function

which gives an error

Overload resolution failed because no accessible 'Select' accepts this number of type arguments.

How can I fix this?

4
  • 1
    Do you have an import for System.Linq? Commented Aug 11, 2017 at 11:12
  • yes, that is why it is saying no select accepts ... Commented Aug 11, 2017 at 11:25
  • that's a very convoluted way of adding 10 to a collection. Note that the value of feeds is ignored and 10 is added all the time. I don't see CType with this converter converter.telerik.com Commented Aug 11, 2017 at 11:46
  • i got this with that converter <System.Runtime.CompilerServices.Extension()> _ Public Function NewLine2(ByVal bytes As Byte(), Optional ByVal feeds As Integer = 1) As Byte() Return bytes.AddBytes(DirectCast(New Byte(feeds - 1) {}, IEnumerable(Of Byte)).[Select](Of Byte, Byte)(DirectCast(Function(x) CByte(10), Func(Of Byte, Byte))).ToArray(Of Byte)()) End Function it still has DirectCast instead, which still gives the error above Commented Aug 11, 2017 at 11:53

1 Answer 1

3

It's not clear to me why specifying the type arguments fails, but that isn't needed anyway - and the location of CType looks to be broken. If you change the Select call to:

.Select(CType(Function(x) CByte(10), Func(Of Byte, Byte)))

then it compiles - but you can also get rid of CType entirely:

.Select(Function(x) CByte(10))

(That simplification works in the C# code too, where this:

.Select<byte, byte>((Func<byte, byte>) (x => (byte) 10))

can be simplified to:

.Select(x => (byte) 10)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.