When looking at a solution with multiple projects:
1) Why do we add a reference to the other project? Can’t we just use inheritance?
2) After we add the reference by using Visual Studio, why do we have to add the project to the namespace system? For example: using myReferenceProject; I thought that the IDE would do that.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using myReferenceProject;
using System.Data.SqlClient;
using System.Data;
They’re two completely different concepts.
Adding a reference to another assembly basically says, “I want to be able to use some of this code. Please make the compiler aware that this code exists, and optionally copy it into the output directory so that it’s present at execution time too.”
How would you expect to use inheritance to create a class derived from some type if the compiler has no knowledge of that type?
Because assemblies and namespaces are different concepts too. A
usingdirective simply says to the compiler “When I refer to typeFoowithin my code, look in these namespaces to try to resolve it.” That type could come from any of the assemblies you’ve referenced.It’s really important that you understand the difference between assemblies and namespaces. Even though they’re often named similarly (
Foo.Bar.dlloften provides types in the namespaceFoo.Bar) they’re conceptually different.