public class Head
{
    public Head()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public string txtTitle;
    public string txtCopy;
    public static string Title(int caseNum)
    {
        OleDbDataReader Config = Class.ExecuteRed("select * from Setting where ID=1");
        if (Config.Read())
        {
            //赋值
            txtTitle = Config["Title"].ToString();
            txtCopy = Config["Copy"].ToString();        }
        Config.Close();
        Config.Dispose();        switch (caseNum)
        {
            case 1: return "'" + txtTitle + "'"; break;
            case 2: return "'" + txtCopy + "'"; break;
        }
        return "";
    }
<%=Head.Title(1)%> <%=Head.Title(2)%> 提示编译器错误信息: CS0120: 非静态的字段、方法或属性“Head.txtTitle”要求对象引用 
大家再帮我看看~~~

解决方案 »

  1.   


     public  static string txtTitle;
        public static string txtCopy;
      

  2.   

    你在静态方法中能引用到非静态的成员变量???
    你这段代码在编译时就会报错吧,,智能感知也不会感知到txtTitle ,txtCopy 这两个字段吧,汗~~
      

  3.   

    类中静态的方法、成员函数只能访问静态的数据成员或者静态的方法。
    Head hd=new Head();
    hd.Title(1)