什么命名空间是我的课的时候,我不把命名空间? [英] What namespace are my classes in when I don't put a namespace?
问题描述
如果我不把一个命名空间,我的课(vs.net 2008),其命名空间做我的课得到下建造?
更新 它的奇怪,当我添加一个命名空间,我似乎无法引用类的方法从我的用户控件。
如果我明确地设置一个名称空间,在我的控制中添加用......,我仍然无法看到它!
这是怎么回事?
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Configuration;
///<总结>
///摘要说明全局
///< /总结>
公共类全局
{
公共全局()
{}
公共静态字符串的ConnectionString
{
得到
{
返回ConfigurationManager.ConnectionStrings [MYDB]的ConnectionString。
}
}
}
我的控制:
使用系统;
使用System.Data这;
使用System.Data.SqlClient的;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
公共部分类MyStats:System.Web.UI.UserControl
{
保护无效的Page_Load(对象发件人,EventArgs的)
{
//等等。
如果你不提供一个命名空间那么你的类型没有命名空间。请记住,命名空间不具有任何意义后编译。他们只是得到追加到你们类型的名称创建之初即有被独特的概率更大更长的名字。
编辑:我认为你可能有两个单独的组件和一个人应该是参考了其他,但事实并非如此。如果两个项目都在一个单一的解决方案,那么类浏览器会显示所有类型的所有项目,但是,这并不一定意味着项目A
引用项目B
。为了以项目A
使用类型由项目B
您需要确保项目引用是否存在。
if I don't put a namespace in my classes (vs.net 2008), which namespace do my classes get built under?
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!
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
. In order to use the types from ProjectB
in ProjectA
you need to ensure that a project reference exists.
这篇关于什么命名空间是我的课的时候,我不把命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!