Function param expects IEnumerable<ClassName>

  • Thread starter Thread starter dh
  • Start date Start date
D

dh

If there is a class member as:

void Function(IEnumerable<ClassName> Param);

What is expected to be passed into this function? A "List"?

Is it OK to code like below?

List<ClassName> myList = new List<ClassName>();

ClassName obj1 = new ClassName();
ClassName obj2 = new ClassName();
....

myList.Add(obj1);
myList.Add(obj2);

Function(myList);
 
If there is a class member as:

void Function(IEnumerable<ClassName> Param);

What is expected to be passed into this function? A "List"?

Any object that implements IEnumerable<ClassName> (List<ClassName> does
happen to qualify said:
Is it OK to code like below?

List<ClassName> myList = new List<ClassName>();

[...]
Function(myList);

It compiles, doesn't it?

Is there some particular problem you're worried about? Is something not
working the way you expect it to?

Pete
 
Back
Top