1
rectangle a=new a() { width=1; height=2; }

I used to construct objects like this, it there a similar way to do this in visual basic? I'm sorry I couldn't really label the technique.

Kjartan
  • 18,591
  • 15
  • 71
  • 96
Uğur Gümüşhan
  • 2,455
  • 4
  • 34
  • 62
  • This is a C# [object initializer](http://msdn.microsoft.com/en-gb/library/vstudio/bb384062.aspx) – Oded Mar 12 '13 at 10:01
  • Possible duplicate: http://stackoverflow.com/questions/3936224/c-sharp-to-vb-net-syntax-conversion-for-class-instantiation-with-properties – Maxim Korobov Mar 12 '13 at 10:05
  • 1
    In an object initializer, use commas not semicolons. You can leave out the `()` in C# when you use the parameterless instance constructor together with an object initializer. The type (class) is hardly called `a` when the variable is `a`. Use `rectangle` or whatever. – Jeppe Stig Nielsen Mar 12 '13 at 10:46

2 Answers2

6

Object initializer in VB.NET:

Dim a = New Rectangle With { .width = 1, .height = 2 }
Oded
  • 489,969
  • 99
  • 883
  • 1,009
-1

The Rectangle has a constructor to define width and height:

Dim r As New Rectangle(1, 1, 200, 300) 'x,y,width,height
SysDragon
  • 9,692
  • 15
  • 60
  • 89