当前位置: 动力学知识库 > 问答 > 编程问答 >

C# Get specific component from list of Components

问题描述:

I have a List of Components

List<Component> components = new List<Component>();

I am designing a dynamic forms framework. I know that casting to a specific component is impossible even if I know what kind of component each of them is. How can I get the component as a specific type (for example TextBox, ComboBox) in order to use their properties.

For example I know that the first item of components is a ComboBox.

Can I get it as ComboBox in order to use it?

网友答案:

Use Enumerable.OfType

Filters the elements of an IEnumerable based on a specified type.

var textBoxes = components.OfType<TextBox>();
分享给朋友:
您可能感兴趣的文章:
随机阅读: