What is automatic properties of .Net 4.0

Posted by Nabanita under C# on 5/8/2011 | Points: 10 | Views : 3170 | Status : [Member] | Replies : 3
What is automatic properties of .Net 4.0?
What is the use of this? OR In which situation we use automatic properties?




Responses

Posted by: Lokesh76 on: 5/8/2011 [Member] Starter | Points: 25

Up
0
Down
As we know that we have following way to implement properties
Public class test

Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
End Class
Now via automatic properties we can do the same thing like

Public class test
Property Name As String
End class


Thanks
Lokesh Kumar

Nabanita, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tijut2k on: 5/9/2011 [Member] Starter | Points: 25

Up
0
Down
Refer this link,it will give the clear idea

http://weblogs.asp.net/scottgu/archive/2010/04/05/automatic-properties-collection-initializers-and-implicit-line-continuation-support-with-vb-2010.aspx

Best Regard's
Tiju Thankachan

Nabanita, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 5/9/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Property is a way of Accessing/Setting field values ( with or without some conditional stage).
In case of automatic properties the compiler creates a field and handles it internally.
lets say you have property named ID
public int ID { get; set; }

Using refelection if you will try to list out all the fields you can see a field something like
<ID>k__BackingField which is created automatically and is not shown .

Thanks,
Debata

Nabanita, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response