从单独的文件访问命名空间

问题描述:

我知道我在这里缺少一些简单的东西,但是如果我有fileA.cs和fileB.cs,其中fileA.cs包含名称空间Access,我理解我可以通过添加文件来利用fileB.cs中的名称空间使用fileB.cs顶部的Access语句。但是,当我从Access命名空间引用项目(如公共字符串)时,我收到错误。我错过了什么?

I know that I am missing something simple here, but if I have fileA.cs and fileB.cs, where fileA.cs contains namespace Access, I had the understanding that I could utilize that namespace in fileB.cs by adding the statement using Access at the top of fileB.cs. However, when I reference an item, such as a public string, from the Access namespace, I receive an error. What am I missing?


我知道我在这里缺少一些简单的东西,但如果我有文件A. cs和fileB.cs,其中fileA.cs包含名称空间Access,我理解通过在fileB.cs顶部使用Access添加语句,我可以在fileB.cs中使用该名称空间。但是,当我从Access命名空间引用项目(如公共字符串)时,我收到错误。我错过了什么?
I know that I am missing something simple here, but if I have fileA.cs and fileB.cs, where fileA.cs contains namespace Access, I had the understanding that I could utilize that namespace in fileB.cs by adding the statement using Access at the top of fileB.cs. However, when I reference an item, such as a public string, from the Access namespace, I receive an error. What am I missing?



您收到的错误是什么?

您是否正确包含了命名空间?

What is the error that you are receiving?
Have you included the namespace properly?


你有代码示例吗?我不确定C#中的语法,但是在VB 2005中你的命名空间如下:

Do you have a code example? I''m not sure exactly of the syntax in C#, however in VB 2005 your namespace would be as follows:

展开 | 选择 | 换行 | 行号



您收到的错误是什么?

您是否正确包含了命名空间?
What is the error that you are receiving?
Have you included the namespace properly?



错误是:当前上下文中不存在名称''strExample''。我意识到这个错误是因为无法从其他文件访问正确的命名空间。


我认为我必须要做的就是为命名空间添加一个using语句。显然事实并非如此。请记住,我打算包含整个文件的命名空间。

The error is: The name ''strExample'' does not exist in the current context. I realize this error is because the proper namespace cannot be accessed from the other file.

I thought that all I had to do to include the namespace was to add an using statement for it. Apparently that is not the case. Keep in mind I am intending to include the namespace for the entire file.