create a namespace in c++/cli?

2019-07-10 17:33发布

问题:

I have seen many examples of using .NET Framework namespaces in c++/cli like the following:

using namespace System;
using namespace System::IO;

But I haven't seen any examples of creating my own. So I was wondering if there is a way to declare/create my own namespace as I would in C#:

namespace Animals
   {

   public class Dog
       {
       public Dog() {}
       }
   }

Thanks for your time :)

回答1:

Same syntax for single namespaces. Nest for multiples, e.g. for First.Second.Third:

namespace First
{
namespace Second
{
namespace Third
{

    // Your code

}
}
}

In C# the same would be:

namespace First.Second.Third
{
}


回答2:

You already know how it should be done, as is demonstrated by your example

namespace NamespaceName //C++/CLI or C#
{
    //contents
}