There is actually a (subtle) difference between the two. Imagine you have the following code in File1.cs:
// File1.cs
using System;
namespace Outer.Inner
{
class Foo
{
static void Bar()
{
double d = Math.PI;
}
}
}
Now imagine that someone adds another file (File2.cs) to the project that looks like this:
// File2.cs
namespace Outer
{
class Math
{
}
}
The compiler searches Outer
before looking at those using
directives outside the namespace, so it finds Outer.Math
instead of System.Math
. Unfortunately (or perhaps fortunately?), Outer.Math
has no PI
member, so File1 is now broken.
This changes if you put the using
inside your namespace declaration, as follows:
// File1b.cs
namespace Outer.Inner
{
using System;
class Foo
{
static void Bar()
{
double d = Math.PI;
}
}
}
Now the compiler searches System
before searching Outer
, finds System.Math
, and all is well.
Some would argue that Math
might be a bad name for a user-defined class, since there's already one in System
; the point here is just that there is a difference, and it affects the maintainability of your code.
It's also interesting to note what happens if Foo
is in namespace Outer
, rather than Outer.Inner
. In that case, adding Outer.Math
in File2 breaks File1 regardless of where the using
goes. This implies that the compiler searches the innermost enclosing namespace before it looks at any using
directive.
Q1
A) No, they keep their filename and are outside of the assembly.
B) No, they keep their filename and are outside of the assembly.
Q2
A) Web References refer to web services that are referenced to in your project. When you add a Web Reference, a proxy is generated to handle the communicatino with the service. That proxy needs to be compiled with your project (the proxy is auto-generated so you don't need to worry about it).
B) Resource files are *.resx included in your project. The most common use for resource files in a web application is internationlization. Those files do get compiled into your application.
Best Answer
Sounds to me like you are expecting Web Application behaviour from a Web Site "project".
In a Web site each ASPX/ASHX file (outside of the App_Code) is considered content. At any point you may wish to simply publish a few of the files to the web site. Hence compiling all them at once into a single assembly is not desirable.
With a Web Application you don't normally publish just a few files, you complete a phase of the application, compile it all together and then publish.
You seem to indicate you have "classes" declared outside of App_Code? Where would they be if not in their own dll project? If in a dll project then you need to create a project reference to in the Web Site properties.