C#:使用引用的 DLL
我创建了一个 DLL 并将其引用到我的项目中,但我不知道如何实际使用它。看来要使其工作,我必须使用一些类似的代码
MyClass class = new MyClass;
,但我仍然无法让它工作。这是我的代码:
using MyClass;
namespace NoName
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MyClass MyClass = new MyClass();
Bitmap bmp = new Bitmap(MainImage.Image);
}
}
}
I've created a DLL and referenced it to my project, but I cannot figure out how to actually use it. It appears that to make it work, I have to use some code like
MyClass class = new MyClass;
But I still can't get it to work. Here's my code:
using MyClass;
namespace NoName
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MyClass MyClass = new MyClass();
Bitmap bmp = new Bitmap(MainImage.Image);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
确保您已引用包含依赖程序中的类库中要使用的类型的命名空间。
在大多数情况下,您要查找的根命名空间应与引用的 dll 的名称相匹配。例如 DLLName.xxx ... 其中“DLLName”将是您的根命名空间,句点后面的任何内容都表示连续层次结构中的子文件夹。
Make sure you have referenced the namespace that holds the types you want to use from your class library in the dependent program.
In most cases the root namespace you are looking for should match the name of your referenced dll. e.g. DLLName.xxx ... where "DLLName" would be your root namespace and the anything after the period would signify child folders in a continuing hierarchy.
如果您不想添加对类名称空间的引用(通过 using 保留字),那么您可以在创建类的实例时完全限定该类:
If you don't wan to add a reference to your class namespace (by means of the using reserved word) then you can completely qualified your class when you create an instance of it:
实际上,当您创建类的实例时,变量名不需要与类的大小写相同。
现在您可以
在发布您正在使用的代码中
使用如果这不是实际问题,那么请给我们一个您想要如何使用 MyClass 的示例(它有哪些方法或属性?)
Actually when you create your instance of your class your variable name needs to not be the same case as your class.
now you can use
In your code posting your were using
If this is not the actual problem then give us an example of how you want to use MyClass (what methods or properties does it have?)
您应该使用
using MyClassNamespace;
,其中MyClassNamespace
是MyClass
的命名空间。You should have
using MyClassNamespace;
whereMyClassNamespace
is the namespace ofMyClass
.