Overloading properties in C#
Posted
by end-user
on Stack Overflow
See other posts from Stack Overflow
or by end-user
Published on 2010-04-09T15:55:52Z
Indexed on
2010/04/09
16:03 UTC
Read the original article
Hit count: 439
Ok, I know that property overloading is not supported in C# - most of the references explain it by citing the single-method-different-returntype problem. However, what about setters? I'd like to directly assign a value as either a string or object, but only return as a string.
Like this:
public string FieldIdList
{
get { return fieldIdList.ToString(); }
set { fieldIdList = new FieldIdList(value); }
}
public FieldIdList FieldIdList
{
set { fieldIdList = value; }
}
private FieldIdList fieldIdList;
Why wouldn't this be allowed? I've also seen that "properties" simply create getter/setter functions on compile. Would it be possible to create my own? Something like:
public void set_FieldIdList(FieldIdList value)
{
fieldIdList = value;
}
That would do the same thing. Thoughts?
© Stack Overflow or respective owner