c#:注意不允许在另一个嵌套的名称空间中声明多部分的名称空间请问高手,这句怎么理解?C#名称空间 嵌套
解决方案 »
- confirm 弹出是和否对话框
- 再开一贴,如何获取动态创建的CheckBox是否被选中
- datagirdview 中ShowCellToolTips 停留时间设置
- 跪求请高人改错
- 如何检验字符串是以“\\.\”开头的?
- 在一个x*x的网格中以某一点为圆心,半径为r画一个圆
- 谢 net_lover(孟子E章) 100分请进 ( 关于SESSION丢失问题的再次提问,散无比多分(500)就为了一个解决 )
- 高分问几个步骤,想把n个图片做到资源文件中,在程序中使用,请问具体步骤如何来做?
- 在北京寻找工作ing......
- 创建C# addin,如何在addin中生成FORM文件,并加上控件?
- 为什么用C#编写的木马修改注册表不执行
- C#用来表示详细信息用什么写!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 试验
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
}
}
那个试验就是命名空间,这个项目所有的命名空间都叫试验
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
namespace A
{
namespace B.C
{
class Program
{
static void Main(string[] args)
{
ConsoleApplication1.A.B.C.Program p;
}
}
}
}
namespace E
{
namespace F.G
{
class Test { }
}
}
}
但是它完全是合法的。
看书很细,这很好,但是不能太纠结啊。
这个话当时我也纠结了,好多朋友还一起分析了,汗啊,其实这个是.net 1.1时代的一个问题,multipart namespace其实就是指的MyNamespace1.MyNamespace2这样的写法,没必要纠结了,因为现在这一条已经不会出问题了,2.0的时候应该编译就不会出问题了。这破书出的太早,有些内容没有做改动和调整,不能与时俱进而已了。
具体参考下面的网站好了(就是wrox的),英文的但还比较好懂,我是看完就不纠结了啊。
http://p2p.wrox.com/c-2005/56590-about-namespace.html。以下是当时我的记录,注意其中下划线的那两句:
解答来自www.wrox.com的论坛,网址http://p2p.wrox.com/c-2005/56590-about-namespace.html
用户:
Hello!Expert.I am learning about C Sharp.I bought a book from bookshop.The book's name is <<Professional C#, 3rd Edition>>.As a result,I have faced a lot of difficulties.Now I want to asked a question.What is the mean of the book's sentence?The sentence is at Page 58,it is "Note that we are not permitted to declare a multi-part namespace nested within another namespace."Please give me a example(Code).Thank you!
专家:
It appears the book in question is based on .Net 1.1.
What they are saying is:
You CAN do this:
namespace Cheese
{
namespace MoreCheese
{
}
}
But you can NOT do this:
namespace Cheese
{
namespace Stinky.Cheese
{
}
}
If you try to compiled the second one in 1.1 you get this error:
error CS0134: Cannot use qualified namespace names in nested namespace declarations
THIS ONLY APPLIES TO .NET 1.1. .Net 2.0 DOES allow this.
用户:
I make sure that the book is wrong!
专家:
It would seem that the book is incorrect. It's also possible that when the book was written, MS hadn't made this change. Given the amount of time it takes to write a book, it's understandable that changes in the software could be made that affect the accuracy of the book.
如果你英文还可以,学习C#最好的去处就是MSDN,每个人思考的角度不同,思路不同描述就会有差别。