Wherewith replace Dictionary.Where(p => p.Key is T)

Posted by abatishchev on Stack Overflow See other posts from Stack Overflow or by abatishchev
Published on 2010-05-18T17:21:00Z Indexed on 2010/05/18 17:40 UTC
Read the original article Hit count: 147

Filed under:
|
|
|
|

I have a System.Collections.Generic.Dictionary<System.Web.UI.Control, object> where all keys can be either type of System.Web.UI.WebControls.HyperLink or type of System.Web.UI.WebControls.Label.

I want to change Text property of each control. Because HyperLink doesn't implement (why??) ITextControl, I need to cast Label or HyperLink explicitly:

Dictionary<Control,object> dic = ..

dic
  .Where(p => p.Key is HyperLink)
  .ForEach(c => ((HyperLink)c).Text = "something")

dic
  .Where(p => p.Key is Label)
  .ForEach(c => ((Label)c).Text = "something")

Are there ways to workaround such approach?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ