You have a variable userNotes
that contains a IList
of the class UserNotes
. To simplify, you can imagine that you have a collection of box on which you wrote an integer (the index of the box in the collection), and the content of each box you have is an instance of the UserNotes
class.
When you write userNotes.
, you target the collection of box. So to access the content of the class UserNotes
, you will have to target a specific box to look the content inside to access the instance. Then only you will be able to access the property SymbolsNotes
.
Another way of visualizing it is like a paper dictionary, it has a lot of translations but you cannot just say to the editor "change the description", you will have to say "change the description of the first word in the dictionary", or "change the description of the word 'banana' ".
In C#, you have multiple possibilities to do it :
Of course many other way exists but I juste wrote 3 of the most commons ways to do it.
And you could it like this :
Use the index
userNotes[0].SymbolsNotes.Add(newSymbolNotes);
Use the First
Linq method
userNotes.First().SymbolsNotes.Add(newSymbolNotes);
use the Single
Linq method
userNotes.Single(/* Condition with lambda expression */).SymbolsNotes.Add(newSymbolNotes);