I have a method which returns a WorkInfo object. It has 2 properties CompanyName and WorkLocation.
It might happen that a person has worked at multiple companies. In this case i want to
-
Return an array of
WorkInfoobject -
After the
WorkInfoobject is returned to calling method, i need to enumerate over it in following wayforeach(WorkItem wRow in WorkInfo) { string s1 = wRow.CompanyName ; string s2 = wRow.WorkLocation; }
How do i achieve this in C# ?
UPDATE :
All i need to do is return a collection of multiple objects of same type and loop over it using ForEach.
eg A datatable returns a collection of datarows and we can loop over it using ForEach(Datarow dr in datatable.Rows)
Similarly, what exactly should i do to return a collection of “WorkInfo” objects which i can loop over using ForEach ?
Here is another attempt:
Notes: quick code — not tested — I used your name conventions (ick CamelCase) etc.
Here is some code that I believe solves your problem: