I am a relatively new to C#. I want to write a method that returns an
'iterable' collection:
TheCollection = MyClass.MethodName();
// Further down, I want to use for .. each
foreach(MyCollectionType ct in TheCollection)
{
//do something
}
The collection will store a specific type (a reference type). Since I
cannot specify the data returned as a const (e.g. in C++, the method
signwould look something like this):
const TheCollection& MyClass::MethodName() const ;
I have a number of questions:
1). What Interface should the TheCollection class implement (Ienumerable
IIRC?)
2). I dont want unnecessary copies of the data (since the object stored
in the collection are quite large) - is there anything special I need to
do, to ensure that it is a reference (to the collection) that is passed
from Methodname() and not a copy of the entire collection?