Check the code.
class DynamicObj : BaseObj {} class BaseObj {} class clientCode { List<DynamicObj> GetFilteredObjs(List<BaseObj> baseList) { // I want to return the sublist of baseList which only have DynamicObj. List<DynamicObj> dList = baseList.FindAll( delegate(BaseObj bo){ // Del1 return bo is DynamicObj; }).ConvertAll<DynamicObj>( delegate(BaseObj bo){ // Del2 return bo as DynamicObj; }); } }
Now it might be a silly question, But my code will have to loop objects 2 times,once for Del1 loop and once for Del2 loop.
Is there any straight way? C# 2.0 only.
Sure: