Skip to content

Multiple files in different namespace

tuine2003

Asked Nov 19, 2004, 9:03 PM EST6 answers
Share
LinkedInX
Hi All, I am just the beginner of C#, and I try to write very simple code of C#. MY question is: if we have more than one file, and each file has its own "namespace" so, how does the main file calls or uses all of there namespace. Ok, let's say this in the simpliest way. Example that I have one file( let's say A) with its namespace named H which contains a class Hello. And, I have another file named Main. which have the "void Main". Now, how do I use the class Hello of the file A Plzzz help. Thanks in advance Tuine

6 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    try add 'using H;' at the beginning
    0
  • 0
    Hi, Thanks for your answering; when I tried to do as you said, the program gave me the error says "are you missing a using directive or an assembly reference" !! ok. here is my program In the file named "Person" I have : ================================================ using System; namespace Per { /// /// Description of Class1. /// public class Person { private string Name; int Age; public Person() { Name = "No Name"; Age = -100; } public Person(string N, int A) { this.Name = N; this.Age = A; } public int getAge { get { return this.Age; } } public string getName { get { return this.Name; } } public void Print() { Console.WriteLine ("This Person's name is: {0} ", this.Name); Console.WriteLine ("And his/her Age is : {0} ", this.Age); } public delegate int addingAge( int a, int b); } } ========================================= and in the file named Main I have : using System; using Per; class Testing { Person P = new Person(); public static void Main(string[] args) { Console.WriteLine("Hello World........!"); } } ===================================================== and the compiler shows the error as I have said it above. Plzzzz Point me out........ thanzzzz
    0
  • 0
    C# is different than Java..... you must make the file Per .dll file then add the Per file to your Project....... right click and choose add reference....then choose Per.dll.... Good luck....
    0
  • 0
    Either you need to compile your Person.cs as assembly, and then add it to your project through Project->Add reference...->Browse..->*select person.dll*, as recommended above. Either you need to add Person.cs file into your project directly. Through Project->Add existing item...->*select person.cs* Hope it'll help.
    0
  • 0
    it's not needed to create an assembly of the namespace. But like Robin panther said the file needs to be part of the solution to make the using directive work. As an example I've created a solution with 2 code files. -------file 1----------------- using System; using Engines; namespace csConsole { class NameSpaces { public static void Main() { V6 v6 = new V6(); Console.Read(); } } } ----------------------------- -------file 2----------------- using System; namespace Engines { public class V6 { public V6() { } } public class V8 { public V8() { } } } ---------------------------- It works and gets no errors.
    0
  • 0
    Ahh'.................. I have got it. Many thanks to you alll.......... Those answers were all helpful Thanks again TuiNe
    0