I have new information to .NET programmers.
We can create or rather I say we can overload the property in VB.NET and C#
But there is a very vast difference in both languages
· VB.NET
Private ReadOnly Property MA() As String
Get
...
End Get
End Property
Private ReadOnly Property MA(ByVal movAvg As String) As String
Get
...
End Get
End Property
Ohh this is working like function overloading! But still its property!
· C#
public string Author
{
set {_author = value;}
get {return _author;}
}
public AuthorEntity Author
{
set {_authorEntity = value;}
get {return _authorEntity;}
}
You will be attempting to overload a function which differs only by return type, and it won't compile. this is why properties can't be overloaded in the way you want - because they are converted to get functions which would only differ by return type.
You can see the difference in both language. And its working!!!
1 comment:
I've seen this before, but how do I use it? Lets say I want to pull data from a spreadsheet cell and store it somewhere. The data might be an integer or a date or a string or a double. If I want to store it in the "Value" property of a class I would need to overload the "Value" property as a string, as double, a date and an integer, but to put the value into the property I now have to know what "type" of data it is. I don't care, I only want to store my data as I would a variant in VB6. Property overloading seems the way to go, but it adds a tremendous burdon.
Post a Comment