c#:注意不允许在另一个嵌套的名称空间中声明多部分的名称空间请问高手,这句怎么理解?C#名称空间 嵌套

解决方案 »

  1.   


    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();
            }
        }
    }
    那个试验就是命名空间,这个项目所有的命名空间都叫试验
      

  2.   

    你学习的应该是C#,而不是什么破书上的话,我告诉你,我也不知道这句话是什么意思,正因为如此,我认为你理解或者不理解,是无关紧要的。按照我的理解,是这样的代码:
    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 { }
            }
        }
    }
    但是它完全是合法的。
      

  3.   

    没仔细看上面的内容啊,我大致猜到猜楼主看的所谓破书是《C#高级编程2008》,哈哈。
    看书很细,这很好,但是不能太纠结啊。
    这个话当时我也纠结了,好多朋友还一起分析了,汗啊,其实这个是.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.
      

  4.   

    只要是人,就会犯错,而且现在很多书都是东拼西凑的,还有很多翻译的,由于译者不懂专业术语导致歧义发生的事情也很多。
    如果你英文还可以,学习C#最好的去处就是MSDN,每个人思考的角度不同,思路不同描述就会有差别。