I have been asked this question in an interview.
Let’s say there is a c# collection that contains items, all of which implement an interface IUpdatable that contains a method Update(). How can one call the update method on all items in a single statement, a one liner in c#?
I did try the foreach on collection and invoking the update() on every item that way. Interviewer said that it is more of a junior developer’s style. He wants something short, in one line.
I didn’t realise it at the time, but there are 2 scenarios here. If the collection is not already of type collection<IUpdatable>, a type casting step is needed first to convert the collection from say collection<object> to collection<IUpdatable>. Any shortcuts for performing this?