C# 访问dll中的方法

C# 访问dll中的方法,c#,dll,C#,Dll,好的,首先,我在我使用dll的项目中设置了引用。 我试图做的是访问我的utils dll中的方法“haha” dll代码 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace Utils { public class

好的,首先,我在我使用dll的项目中设置了引用。 我试图做的是访问我的utils dll中的方法“haha”

dll代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Utils
{
    public class kb
    {
        public class yes {
            public void haha(string yes)
            { 
             int test = Convert.ToInt32(yes);
            }
        }
    }
}
在这个项目中,我试图访问哈哈,我只有“Utils.kb.yes”,但没有方法。。我所能做的就是Utils.kb.yes.equals和Utils.kb.yes.ReferenceEquals。

因为
haha()
是一个实例方法,所以您需要先创建
Utils.kb.yes
类的实例:

Utils.kb.yes kb = new Utils.kb.yes();
kb.haha("nextproblem");
或者,您也可以将该方法设置为静态:

public class yes {
    public static void haha(string yes)
    { 
        int test = Convert.ToInt32(yes);
    }
}
然后你可以这样称呼它:

Utils.kb.yes.haha("I am static!");
由于
haha()
是一个实例方法,因此需要创建
Utils.kb的实例。是的
类首先:

Utils.kb.yes kb = new Utils.kb.yes();
kb.haha("nextproblem");
或者,您也可以将该方法设置为静态:

public class yes {
    public static void haha(string yes)
    { 
        int test = Convert.ToInt32(yes);
    }
}
然后你可以这样称呼它:

Utils.kb.yes.haha("I am static!");

你的类没有构造函数,除此之外,在实例化一个对象之前,你不能对一个类做太多的事情。因此,您应该引用dll,然后首先创建一个新对象。然后,您可以从该对象中引用您的方法。

您的类没有构造函数,除此之外,在用类实例化对象之前,您不能对类做太多工作。因此,您应该引用dll,然后首先创建一个新对象。从该对象中,您可以引用您的方法。

顺便说一句,它是
Convert.ToInt32
。是的,我只是在那里放了一些东西,这样它就不那么空了。
Convert.ToInt32
顺便说一句。。是的,我只是在那里放了一些东西,这样它就不那么空了。。谢谢!我完全忘了我必须那样做!第一次dll制作:)谢谢!我完全忘了我必须那样做!第一次制作dll:)