Saturday, July 6, 2013

CSharp C# Multiple Namespaces in the same file

CSharp C# Multiple Namespaces in the same file


TOC
Using reference inside of other namspace
Fully Qualified Name (FQN) without using reference



Using reference inside of other namspace:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace TestingStuff
{
   using AnotherNamespace;
   class Program
   {        
       static void Main(string[] args)
       {
           MyOtherNamespaceClass testA = new MyOtherNamespaceClass();


           Console.WriteLine("press enter to finish");
           Console.ReadLine();
       }
   }
}
namespace AnotherNamespace
{
   class MyOtherNamespaceClass
   {
       public MyOtherNamespaceClass()
       {
           Console.WriteLine(("Created another MyOtherNamespaceClass"));
       }
   }
}



Fully Qualified Name (FQN) without using reference:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace TestingStuff
{    
   class Program
   {        
       static void Main(string[] args)
       {
           AnotherNamespace.MyOtherNamespaceClass testA = new AnotherNamespace.MyOtherNamespaceClass();
           Console.WriteLine("press enter to finish");
           Console.ReadLine();
       }
   }
}
namespace AnotherNamespace
{
   class MyOtherNamespaceClass
   {
       public MyOtherNamespaceClass()
       {
           Console.WriteLine(("Created another MyOtherNamespaceClass"));
       }
   }
}


1 comment: