Newbie Namespace Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

The following code snippet doesn’t compile with,

helloworld.cs(25,39): error CS0246: The type or namespace name 'Library' could not be found (are you missing a using directive or an assembly reference?)

Why can’t the “Library†namespace be found when its location “Company.Application†has been referenced in the Tester class.

using System;

namespace Company.Application.Library
{
class Math
{
public static int Add(int a, int b)
{
return(a + b);
}
}
}

namespace Test
{
using Company.Application;

class Tester
{
static void Main()
{
int iResult = Library.Math.Add(2, 2);
Console.WriteLine(iResult);
}
}
}
 
Yaiz said:
The following code snippet doesn?t compile with,

helloworld.cs(25,39): error CS0246: The type or namespace name
'Library' could not be found (are you missing a using directive or an
assembly reference?)

Why can?t the ?Library? namespace be found when its location
?Company.Application? has been referenced in the Tester class.

Namespaces aren't hierarchical as far as the compiler (or framework) is
concerned.

See http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85570.aspx for
more information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top