[英]What namespace are my classes in when I don't put a namespace?
if I don't put a namespace in my classes (vs.net 2008), which namespace do my classes get built under? 如果我没有在我的类中添加命名空间(vs.net 2008),我的类是在哪个命名空间下构建的?
update Its strange, when I add a namespace I can't seem to reference the classes methods from my user control.
更新它很奇怪,当我添加一个命名空间时,我似乎无法从我的用户控件引用类方法。
If I explicitly set a namespace, and add a 'using ...' in my control, I still can't see it! 如果我明确设置一个命名空间,并在我的控件中添加一个'using ...',我仍然看不到它!
How can this be? 怎么会这样?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
/// <summary>
/// Summary description for Globals
/// </summary>
public class Globals
{
public Globals()
{ }
public static string ConnectionString
{
get
{
return ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString;
}
}
}
My control: 我的控制:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MyStats : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//etc.
If you do not provide a namespace then your type has no namespace. 如果您不提供命名空间,那么您的类型没有命名空间。 Remember that namespaces don't have any meaning post-compile.
请记住,命名空间在编译后没有任何意义。 They simply get appended to the beginning of you type's name to create a longer name that has a greater probability of being unique.
它们只是附加到您键入名称的开头,以创建一个更有可能是唯一的更长名称。
Edit: I think that you may have two separate assemblies and one ought to be referencing the other but it is not. 编辑:我认为你可能有两个独立的程序集,一个应该引用另一个,但事实并非如此。 If two projects are in a single solution then the class viewer will show all types from all projects but that does not necessarily mean that
ProjectA
references ProjectB
. 如果两个项目在一个解决方案中,那么类查看器将显示所有项目中的所有类型,但这并不一定意味着
ProjectA
引用了ProjectB
。 In order to use the types from ProjectB
in ProjectA
you need to ensure that a project reference exists. 要在
ProjectA
使用ProjectB
中的类型,您需要确保存在项目引用。
as you said, that class will not have any namespace, It will be accessible without a using clause. 如你所说,该类没有任何命名空间,没有using子句就可以访问它。
Namespaces is a feature for putting order on your classes, by classifying, mostly according to their funcionality 命名空间是一种功能,通过分类,主要根据其功能,对您的类进行排序
EDIT 编辑
According to your update, i think your "global" class maybe putting trouble because of the global:: clause... would you mind to change the name of the class just to see if it works? 根据你的更新,我认为你的“全局”类可能会因为global :: clause而引起麻烦...你是否想改变类的名称只是为了看它是否有效?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.