使用名称空间重用类的问题 [英] problem with using namespace for reuse a class

查看:62
本文介绍了使用名称空间重用类的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上课并保存了所有内容
为了在新类中重用它,我添加了它(debug/BankLib.exe)以引用并使用它的命名空间....
但是它有找不到命名空间的错误!!!!!!
"

I have class and save all it
for reuse it in new class i add it ( debug/BankLib.exe) to reference and using it''s namespace....
but it has error that can not find the namespace!!!!!!
"

Error   1   The type or namespace name 'BankLib' could not be found (are you missing a using directive or an assembly reference?)   D:\Users\Roham\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.cs   10  7   WindowsFormsApplication1

"

我该怎么办?

"

what do i do with this error?

推荐答案

我不确定我是否正确理解了您的问题.我假设以下内容:

1.您有一个在控制台应用程序项目中使用过的类.
2.现在,您想在另一个项目(Windows窗体项目)中重用该类,并为此添加了对控制台应用程序项目的引用.
3.您遇到了上面提到的错误.

如果假设正确,则需要将Class放入Class库项目中,确保它已生成,然后在Windows Forms项目中添加对该类库的引用(您不能添加对控制台项目的引用并使用一个类来自那个项目).

另外,您需要在尝试使用该类的地方导入该类的名称空间.
I am not sure whether I understood your question properly. I am assuming the following:

1. You have a class that you''ve used in a Console application project.
2. You now want to reuse the class in another project (A windows forms project) and for that you added a reference to the Console application project.
3. You are getting the above error you mentioned.

If the assumptions are correct, you need to put the Class in a Class library project, make sure it builds and then add a reference to that class library in your windows forms project (You cannot add a reference to a console project and use a class from that project).

Also, you need to import namespace of that class where you are trying to use that class.




您的问题不清楚.

我的理解是,您编写了一个包含函数和变量的类(* .cs或* .vb),并且希望在另一个项目中使用它们.

如果是这样,请在Visual Studio IDE中打开您的新项目,然后执行以下操作,
项目->添加现有项目.然后浏览类文件并将其添加到您的项目中.

问候,
Suresh
Hi,

Your question is not clear.

My understanding is that, you have written a class (*.cs or *.vb) with function and variables and you want to use them in another project.

If so, open your new project in Visual studio IDE and do the following,
Project -> Add Existing Item. and then browse the class file and add it in your project.

Regards,
Suresh


要重用类,必须将类构建为dll.为此,创建一个类库,构建它并在另一个类中引用dll.使用引荐来源网址类的名称空间.创建该类的对象,并且在引用程序类中具有访问说明符public的所有方法将在当前类中可用.
For reusing a class you have to build the class to a dll. For that create a class library ,build it and refer the dll in another class. Use the namesapce of the referrer class. Create a object of the class and all the methods with access specifier public in referrer class will be available in current class.


这篇关于使用名称空间重用类的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆