Read this article in your language IT | EN | DE | ES
I know it’s been out for a little while now and most everyone that codes in C# knows but C# 3.0 has a new feature called Automatic Properties. Objective-C for the iPhone has this ability as well, so I was kind of getting pampered in the XCode development environment using Obj-C. I do a lot of VB.Net and sad to say that it doesn’t exist yet for VB.Net. However it will with VB.Net v10 as mentioned a the Professional Developer Conference.
So in C# the old way…
private string _userName;
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
becomes…. in C# v3.0
public string UserName {get; set;}
Your private properties are created for you by the compiler. Yes, yes you already know all this. Great. Why am I posting? Just that I felt VB.Net was getting no love and have been using a similar method in Objective-C.
In Objective-C you synthesize your properties, which basically means the same thing. In your header files you define the property with the property tag
@property int maximumNumberOfSides;
then in your implementation file you create a single line
@synthesize maximumNumberOfSides;
So in the upcoming VB.Net (Visual Basic.Net) v10..
9 lines of code…
Private _UserName As String
Private Property UserName() As String
Get
Return _UserName
End Get
Set(ByVal value As String)
_UserName = value
End Set
End Property
becomes 1!
Public Property UserName As String
I’m so happy, I could cry.
aa2783eb-5eb0-4c88-b0b5-5a35fb21a09e|1|5.0
Programming, VB.NET, C#, Objective-C
programming, vb.net, c#, objective-c, obj-c, properties, automatic properties