I want to give a certain linked list to a class I am making. I want the class to write into that list (eg by .addLast()).
Should I use the ref
keyword for that?
I am somewhat puzzled on where to use the ref
and out
keywords in C#, as all classes are allocated dynamically on the heap and we actually use pointers for most operations.
Of course, out
and ref
keywords make sense for primitives and structs.
Also, if I don't send the list directly, but send a class containing the list? (it's internal
and needed), do I still need to use ref
? or if I pass it between functions, ex:
void A(ref LinkedList<int> list){
B(list);
}
void B(ref LinkedList<int> list){
_myList = list;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…