此代码vb.net的等效点网2.0 [英] Dot net 2.0 equivalent for this code vb.net
本文介绍了此代码vb.net的等效点网2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎此代码需要.NET Framework 3.5,我需要在.net 2.0框架中使用相同的代码,代码如下.
It seems this code required .Net framework 3.5, i need same equivalent in .net 2.0 framework,code is below.
Dim rtb As RichTextBox = Me.Controls.OfType(Of RichTextBox)()
推荐答案
OfType不会产生单个元素,而是它们的集合(IEnumerable). 参见此处 [
OfType does not produce a single element but rather a collection (IEnumerable) of them. See here[^].
You can reproduce theOfType
extension method in .NET 2.0 along these lines:
List<RichTextBox> widgets = new List<RichTextBox>();
foreach(Control control in this.Controls)
{
// If it is of type RichTextBox add it to the list
// In VB.NET the condition would be like: TypeOf control Is RichTextBox
if(control is RichTextBox)
widgets.Add((RichTextBox)control);
}
}
这个例子在C#中,但是我希望您能理解发生了什么.
问候,
曼弗雷德(Manfred)
This example is in C#, but I hope you can understand what is going on.
Regards,
Manfred
这篇关于此代码vb.net的等效点网2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文