Reputation: 6585
It is possible for the type returning by a property's get
accessor to be different from the type used by the set
accessor?
private string[] artists;
public string[] Artists
{
get { return artists[0]; } //heree getter return string than string[]
set { artists = value; OnPropertyChanged("Artist"); }
}
Upvotes: 1
Views: 592
Reputation: 273701
No, this won't work.
You could add another property, and include it in the ONPC:
public string Artist
{
get { return artists[0]; }
}
public string[] Artists
{
// get { return artists; } // get string[] is optional
set { artists = value; OnPropertyChanged("Artist"); OnPropertyChanged("Artists");}
}
Provide a sample of intended use with some context and you might get a better answer.
Upvotes: 2
Reputation: 28738
No, not possible. It is plain to see that your code is illegal, because your get accessor does not fulfil it's obligation to return a string[]
// you define the Artists property as a string[],
// therefore the get accessor must return a string[]
public string[] Artists
{
// you are returning only a string
get { return artists[0]; }
Upvotes: 0
Reputation: 1911
Why should this be possible. If you declare the return type then this HAS to be returned.
Upvotes: 0
Reputation: 3338
No this is not possible. You have to create another property to return another type.
Upvotes: 1