Please, let me give an example.
Say, we have:
- a CheckedListBox control enumerating names of some regular expression groups.
- a TextBox control where a user can print some input text
- a Button which makes the programm check, if the input text matches the regular expression and show the values of the checked (in our CheckedListBox) groups to the user.
Let the button click event handler look like this:
Regex r = new Regex(@"^(?<Num5>\d{1,5})\:(?<SomeText>.{1,})$");
Match m = r.Match(textBox1.Text);
if (m.Success)
{
MessageBox.Show(
string.Concat(
checkedListBox1.CheckedItems
.OfType<string>()
.Where(s => m.Groups[s].Success)
.SelectMany(s => string.Format("{0}: {1}\n",
s,
m.Groups[s].Value))));
}
else
MessageBox.Show("Input text didn't match");
So, is there an opportunity to obtain the LINQ functionality from the Collection similar to the CheckedItemCollection (implementing similar interface list) without explicit usage of OfType or Cast methods?
P.S.: this is only an example, so, please, don’t be too critical about it..
No, the CheckedItemCollection is non-generic and the compiler would not know what objects are you dealing with.
Using
is the best you can do.