المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : a better way to make, and populate, a List ?



C# Programming
08-08-2012, 09:31 AM
Current working code in a public static class: a List used internally:// required directives [1]:using System;using System.Windows.Forms;using System.Collections.Generic;////private static List OkToModify = new List { typeof(CheckBox), typeof(TextBox), typeof(Button), typeof(Panel), typeof(Label)};By "working:" I mean that I can use the List to test if a given Control passed into the public static class is okay for the uses I make of it. Through, simply:if (OkToModify.Contains(cntrl.GetType())) { processControl(cntrl) };I keep thinking that somewhere in my reading (Skeet ? StackOverFlow ?), or here on CP, I have seen a "niftier" way to do this.

Appreciate any alternatives.

thanks, Bill

[1] edit: 'references changed to 'directives in response to feedback from PIEBALDconsult. However, they are, indeed, "required."
"Everything we call real is made of things that cannot be regarded as real." Niels Bohr