Change return type of property to array of strings:
public string UserName { get; set; }
public string[] UserNameSeparated
{
get { Username.Split('-'); }
set
{
UserName = String.Join("-", value);
}
}
Usage:
foo.UserName = "10-1685";
string[] names = foo.UserNameSeparated;
// names[0] = "10";
// names[1] = "1685";
foo.UserNameSeparated = new string[] { "15", "42" };
// foo.UserName = "15-42"
BUT consider to have properties for both parts of name. You will be able to calculate full name at any time, and you will deal with nice named properties instead of tuples or array indexes (support hell):
public string FirstName { get; set; }
public string LastName { get; set; }
public string UserName
{
get { return String.Format("{0}-{1}", FirstName, LastName); }
set
{
// check if value format valid
var names = value.Split('-');
FirstName = names[0];
LastName = names[1];
}
}
Just compare (you can give more descriptive names, which describe your data better):
foo.FirstName
foo.LastName
With:
foo.UserNameSeparated.Item1
foo.UserNameSeparated.Item2