I have code that looks like this;
public ObservableCollection<ParamViewModel> ListOfPhrases{
get => _listOfPhrases;
set => SetProperty(ref _listOfPhrases, value);
}
public class ParamViewModel : ObservableObject
{
bool _selected;
int _id;
string _name;
string _state;
public bool Selected { get => _selected; set => SetProperty(ref _selected, value); }
public int Id { get => _id; set => SetProperty(ref _id, value); }
public string Name { get => _name; set => SetProperty(ref _name, value); }
public string State { get => _state; set => SetProperty(ref _state, value); }
}
private void OnPhraseTapped(string btnText)
{
ListOfPhrases.ForEach(x => x.Selected = false);
var first = ListOfPhrases.FirstOrDefault(x => x.Name == btnText);
if (first != null) first.Selected = true;
So when the btnText is ABC it populates first with an element of the ListOfPhrases list. Then the value of first is set to true.
My question is. Why does changing the Selected value of first change an entry in the ListOfPhrases?
If I create this code:
var a = "ABC";
var b = a;
b = "x"
then I believe changing b
doesn't change the value of a