Object Initializers in VB.Net
By Anuraj P on June 21st, 2008 . No Comments .
In my last post I have used a special syntax for creating instance of Person Class.
VB.Net
Dim p as New Person With {.Name = “Person1″, .Age = 20}
C#
Person p = New Person {Name = “Person1″, Age = 20};
Which is equivalent to
VB.Net
Dim oPerson as new Person oPerson.Name = "Person1" oPerson.Age = 20
C#
Person oPerson = new Person(); oPerson.Name = "Person1"; oPerson.Age = 20;
This is another new feature introduced in VB.Net 9.0, called Object Initializers. You can get more information about this in MSDN. Actually I am planning to write a post on the feature newly available in VB.Net 9.0
No Responses to “Object Initializers in VB.Net”
RSS feed for comments on this post. TrackBack URL
Actually, the C# code is equivalent to something like this:
Person tempPerson = new Person();
tempPerson.Name = "Person1";
tempPerson.Age = 20;
Person oPerson = tempPerson;
I do not know about the VB.Net code, but I expect a similar situation.
Comment by lagattack — August 18, 2008 @ 4:36 pm
lagattack, Sorry I can’t understand your comment.
Comment by anuraj — August 22, 2008 @ 5:13 pm