Q: Projects/Solution & classes

  • Thread starter Thread starter Geoff Jones
  • Start date Start date
G

Geoff Jones

Hi

I'm starting to look at C# after programming in C++ and was wondering if
anybody could help me with the following questions:

(1) What is the difference between a Project and Solution In Visual Studio
..NET?

(2) When programming in C++, to allow a file/class to know about other
classes, I normally include a header file in the source file of the class.
However, C# does not have header files i.e. all are written inline, and I
don't quite understand how one class would "know" about another class in
another file. I tried a small test application by creating a default Windows
application and then adding a new class. The main application file seemed to
know about this new class without adding an "include". Can anybody explain
what is going on?

Thanks in advance

Geoff
 
Hi
I'm starting to look at C# after programming in C++ and was wondering if
anybody could help me with the following questions:

(1) What is the difference between a Project and Solution In Visual Studio
..NET?

A project is typically the collection of files needed to compile one
particular assembly, usually .DLL or .EXE. A solution can contain many
projects.
For instance an application might have a solution consisting of four
projects: the main .EXE (front end), a couple of .DLLs (one the back-end, and
one a windows forms component), and a setup project (*.msi/setup.exe).
Everything has to be in the same language, but only within the context of a
single project. Thus, a solution can have one of the projects in C#, one in
VB.NET, and one in C++ if it wants, and they will all interop together if
wired up correctly.
(2) When programming in C++, to allow a file/class to know about other
classes, I normally include a header file in the source file of the class.
However, C# does not have header files i.e. all are written inline, and I
don't quite understand how one class would "know" about another class in
another file. I tried a small test application by creating a default Windows
application and then adding a new class. The main application file seemed to
know about this new class without adding an "include". Can anybody explain
what is going on?

If you do this, then the IDE will by default give it the same namespace as
the Form1.cs class file that your project starts with. Which means it will
know about it. The compiler has "read-ahead" functionality unlike C++, which
means it doesn't need to have seen that class *by the time* it first sees a
reference to it. It reads the whole project in, *then* begins to analyse it.
If a class that you are trying to use is defined anywhere within the
namespace you are trying to use it in, then it can see it.

If it's *not* in the same namespace (as might be the case when it's in
another assembly, like a .DLL, possibly a .NET framework one) then it will
only see it if you either fully qualify the class name by prefixing it with
the namespace name that it's in wherever you use it, *OR*, the file you use
it in is "using" the namespace that the DLL is in (you must have seen the
"using [namespacename]" statements at the top of a file.) AFAIK, "using
[namespacename]" statements are file-by-file.
 
Back
Top