0

I have the following vb.net line:

Dim applesAs Object() = New Object([end] - startIndex - 1) {}

and Developer Fusion's Converter converts it to this c# line:

object[] apples= new object[end - startIndex - 1];

The c# code seems to create an array of objects called apples, however I cannot find what the constructor for Object in vb is doing. Is it also creating an array? Am I wrong about what the c# line seems to be doing?

6
  • 1
    It's just predetermining the size of the object array. It's not a constructor it is an array initializer. Commented Sep 17, 2013 at 15:19
  • Your vb code looks as if it was translated from C# earlier ... (because that syntax is very unfamiliar for vb) Commented Sep 17, 2013 at 15:21
  • 2
    In C#, you use the size of the array, while in VB you use the upper bound, so the conversion should be: object[] apples = new object[end - startIndex]; Commented Sep 17, 2013 at 15:32
  • 1
    @igrimpe: what part doesn't look like VB? Commented Sep 17, 2013 at 15:33
  • @DaveDoknjas: Everything after and including the "=". Why wouldnt a VB guy simply write: Dim apples(maxindex) As Object ? Commented Sep 17, 2013 at 15:42

2 Answers 2

7

however I cannot find what the constructor for Object in vb is doing.

Its not a constructor call,() are used in VB.Net for array indexing.

Also there is no constructor accepting a parameter with Object

Sign up to request clarification or add additional context in comments.

Comments

3

Both the vb.net and c# code are creating an object array called apples.

  • c# uses [] to indicate an array
  • vb.net uses () to indicate an array

The parameters set the size of the array

new Object(5) 'vb.net
new object[6] //c#

2 Comments

In C#, that would be "new object[6]" since the VB code specifies the upper bound, not the size.
@DaveDoknjas Thanks for that bit of info. I was not aware of that! I am new to vb.net.

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.