无法找到命名空间名称"Control"的类型(您是否缺少using指令或程序集引用?)

fla*_*404 2 .net c#

尝试使用泛型在.Net 3.0中设置扩展方法,我收到一条错误消息,上面的详细信息如下:

foreach(Control childControl in parent.Controls)
Run Code Online (Sandbox Code Playgroud)

我错过了使用指令或汇编引用吗?

谢谢

我想要做的是将其设置为(下面)作为扩展函数:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;

namespace System.Runtime.CompilerServices
{
    public static class ControlHelper
    {
    public static T FindControl<T>(this Control parent, string controlName) where T : Control
    {
        T found = parent.FindControl(controlName) as T;
        if (found != null)
            return found;
        foreach (Control childControl in parent.Controls)
        {
            found = childControl.FindControl(controlName) as T;
            if (found != null)
                break;
        }
        return found;
    }
}
}
Run Code Online (Sandbox Code Playgroud)

我错过了对system.core.dll的引用...它让我疯了!

Sam*_*ell 9

选择您正在使用的技术:

Windows窗体:

它位于System.Windows.Forms.dllSystem.Windows.Forms命名空间.

WPF :(可能不是这个,因为ControlsWPF类中没有相关属性)

它位于PresentationFramework.dllSystem.Windows.Controls命名空间.

网络控制:

它位于System.Web.dllSystem.Web.UI命名空间.