I've List Tuple with int and string in it, each time I add new position to this list, I check for the same string in already added elements. Once I see the same - the goal is to change int (to do +1). For example if we have (3, box; 1, apple; 2, PC) and we need to add "apple", so I must change existing "1, apple" to "2, apple". But I can't do it because Item1 return error "The property has no setter". Where my mistake? Thanks.
string[] elements = s.Split(); // Contains all elements as strings.
List<Tuple<int, string>> elementsList = new List<Tuple<int, string>>();
var sortItems = elementsList.OrderBy(x => x.Item1);
for (int i = 0; i < elements.Length; i++)
{
foreach (var item in sortItems)
{
if (Equals(item.Item1, elements[i]))
{
item.Item1 += 1;
}
}
elementsList.Add(new Tuple<int, string>(1, elements[i]));
}
return elementsList;