New Oject() {} vs. New Object(-1) {}

  • Thread starter Thread starter stand__sure
  • Start date Start date
S

stand__sure

This has bugged me for some time.

Is there any "behind the scenes" difference between the following two
snippets?
Dim obj1 As Object = New Oject() {}
Dim obj2 As Object = New Object(-1) {}
Thanks!
 
Apart from the obvious typos', I would suggest that there is no significant
difference.

Try:

Dim obj1() As Object = New Object() {}
Dim obj2() As Object = New Object(-1) {}
Console.WriteLine(obj1.Length)
Console.WriteLine(obj1.GetLowerBound(0))
Console.WriteLine(obj1.GetUpperBound(0))
Console.WriteLine(obj2.Length)
Console.WriteLine(obj2.GetLowerBound(0))
Console.WriteLine(obj2.GetUpperBound(0))

and observe the results.
 
stand__sure said:
This has bugged me for some time.

Is there any "behind the scenes" difference between the following two
snippets?
Dim obj1 As Object = New Oject() {}
Dim obj2 As Object = New Object(-1) {}

After some corrections ('obj1()', 'obj2()', 'Oject' -> 'Object') there is no
difference, not even behind the scenes, between the two lines.
 
Thanks for the replies (and for tolerance of the typo).

I had seen no difference in the debugger, but the guidance from microsoft
was to use "New Object(-1) {}" to create an empty array -- the form "New
Object() {}" is more intuitive...
 
stand__sure said:
Thanks for the replies (and for tolerance of the typo).

I had seen no difference in the debugger, but the guidance from microsoft
was to use "New Object(-1) {}" to create an empty array -- the form "New
Object() {}" is more intuitive...

I'd use the latter form.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top