score:11

Accepted answer

How about:

return _tabs.OfType<EditorTabViewModel>().Any(t => t.CanSave);

Here:

  • OfType<> is a non-buffering filter that restricts us to EditorTabViewModel
  • Any is short-circuiting, so returns true as soon as a match is found

score:1

Using the linq extensions you could write something like

_tabs.Any( p => p is EditorTabViewModel && ((EditorTabViewModel)t).CanSave)

score:1

Try something like:

return _tabs.FirstOrDefault(y => y is EditorTabViewModel && ((EditorViewModel)t).CanSave) != null;

score:2

Yes, you can improve. Something like this would probably work:

return _tabs.Any(x => x is EditorTabViewModel && ((EditorTabViewModel)x).CanSave);

Related Articles