C# Can';看不到dll类的方法

C# Can';看不到dll类的方法,c#,C#,我已使用此类创建了一个dll: namespace Trace { /// <summary> /// Get the stack /// </summary> public class Tracers { public string getTrace() { return "test"; } } } 但我得到: 它必须是属性、方法或字段的引用,而

我已使用此类创建了一个dll:

namespace Trace
{
    /// <summary>
    /// Get the stack
    /// </summary>

    public class Tracers
    {
        public string getTrace() 
        {
            return "test";
        }
    }
}
但我得到:

它必须是属性、方法或字段的引用,而不是静态的“Trace.Tracers.getTrace()”

我不知道我做错了什么。另一件奇怪的事情是,如果我只写
跟踪器。
intellisense菜单出现并仅显示:

  • 相等于
  • 引用等于

  • 您没有
    跟踪器的实例,因此只有静态方法可见

    使方法
    静态
    将起作用:

    public static string getTrace() 
    {
        return "test";
    }
    
    或创建跟踪程序的实例

    Tracers t = new Tracers();
    t.getTrace(); 
    
    还请注意,命名约定要求
    getTrace
    使用大写字母
    G
    ,因此:
    getTrace

    使用以下命令:

    Tracers t = new Tracers();
    t.getTrace(); 
    

    您必须将方法设置为
    静态
    ,如下所示

    namespace Trace
    {
        /// <summary>
        /// Get the stack
        /// </summary>
    
        public class Tracers
        {
            public static string getTrace() 
            {
                return "test";
            }
        }
    }
    
    或者,若要使用当前代码,则需要在方法调用之前实例化类

    Tracers trace = new Tracers();
    trace.getTrace(); 
    

    哦,谢谢你,我犯了个愚蠢的错误。。祝你过得愉快:)你迟到了11分钟。
    Tracers.getTrace(); 
    
    Tracers trace = new Tracers();
    trace.getTrace();