The Artima Developer Community
Sponsored Link

C# Answers Forum
Namespace

3 replies on 1 page. Most recent reply: Jan 6, 2004 9:09 AM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
sdinesh79

Posts: 7
Nickname: sdinesh79
Registered: Sep, 2003

Namespace Posted: Dec 25, 2003 7:55 PM
Reply to this message Reply
Advertisement
Hi Guys,

I am new to C#.
I have two files saved in the same directory.
The first file:
namspace First{
       class First{
            public int i=1;
       }
        
       class Second{
            public static void Main(){
                  Console.WriteLine("{0}",i);
            }
}
        
The second file:
 
using System;
using First;
 
namspace Third{
       class Third{
            First f = new First();
       }
}


When I compile the second file it says "namespace First not found"!!.I tried different ways but....
How can I solve this???
Any help appreciated.


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Namespace Posted: Jan 2, 2004 3:01 AM
Reply to this message Reply
You probably didn't include the "/reference" parameter to the compiler? You compile the First one first, then when you compile the second one (Third), you need to tell it what other assemblies to refer to. Hmm, this is starting to remind me of the old Abbott and Costello routine... I'm assuming you are doing this all on the command line (the IDE would automatically do this for you if they are in the same project).

By the way, I think having namespaces and classes with the same names is going to cause a bit of confusion...

sdinesh79

Posts: 7
Nickname: sdinesh79
Registered: Sep, 2003

Re: Namespace Posted: Jan 6, 2004 3:57 AM
Reply to this message Reply
Hi Matt,
Thank u for the reply.

I tried this code in both command line and IDE(VisualStudio.NET) but both have come up with the same result "namespace First not found".Both are not in the same project.How to do it in IDE if both are not in the same project?

Also may I have an example of how to do it using /reference.Is it like
"csc /reference:First.cs Third.cs" if the first assembly name is First.cs.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Namespace Posted: Jan 6, 2004 9:09 AM
Reply to this message Reply
First you need to compile First into an assembly. For the following, let's assume you did that and called it "Cardinal.dll"

Next:

In the IDE, in the "Solution Explorer" tool window, you right-click the project and choose "Add Reference..." and from there you can browse to the assembly that contains First, "Cardinal.dll" and add it.

Alternatively, on the command line, you might do something like this:

csc /reference:d:\path\Cardinal.dll Second.cs

(you might also use /standalone if you want to make it an exe, as well as other options you can find with "csc /?")

Flat View: This topic has 3 replies on 1 page
Topic: input numbers, output numbers Previous Topic   Next Topic Topic: Any not banded report engine for C#?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use