I need help understanding how C # projects are organized in Visual Studio

I've been teaching myself C # for the past two weeks, and as someone whose IDE of choice is Notepad, I have a little harder time migrating to Visual Studio (I'm using Express 2010). In particular, I'm wondering how the organization of the Namespace-Class-Method hierarchy manifests itself VISUALLY in the interface. I find it difficult to figure this out, and more importantly, how to use the interface to effectively organize and track my projects.

For example, there is a "solution explorer" but there is no such thing as a C # "solution" (which I know). I suspect Microsoft marketing is talking about a more general development timeline, but I can't figure it out. I get the opportunity to create new "projects". Is "project" a "solution"?

I am also a bit fuzzy on namespaces. I suspect the namespaces are the Java equivalent of a class library. What are examples of how namespaces are used in the real world? Let's say for example I am developing a personal finance application. Would I put EVERYTHING related to this application in one solution? Or will I create a namespace for example for cash accounts and namespaces for investment accounts?

My * .cs files are in namespaces, but I cannot figure out how to create a NEW * .cs file in my namespace. I would use EXPECT based on the explorer hierarchy so that any class using the namespace appears in this list and I could use it as needed. For example, I could create enterDeposits.cs and enterWithdrawals.cs WITHOUT having to create a new project.

I found a couple of tutorials online that tell me how to do things (like creating a new project), but without a deep understanding of the IDE vocabulary, I'm not sure if I will organize everything as I could. Help!

+3


source to share


3 answers


Solutions and projects in Visual Studio are ways of organizing code — they are containers used by the IDE to issue commands to the compiler and other assembly components as needed.

Solutions contain projects - Projects contain code files.

Each project will be compiled into a separate DLL or EXE, a deployment unit.

Namespaces can be shared between projects and solutions and can be found in different DLL / EXE libraries. They are logical separation units.

In Visual Studio, you can set a base namespace for each project in its properties. By default, every directory you create will be added to it as part of the internal namespace. Any source file created in the directory will get this namespace by default.



In general, namespaces are pure code constructs.

In a C # file, you have a declaration namespace

- it can be any valid namespace identifier and can be in any project / solution / code.

I suggest taking a look at MSDN - it's a good resource for any C # and Visual Studio.

+7


source




+1


source


Excellent review of Oded. RE: will EXPECT based on the explorer hierarchy so that any class using the namespace appears in this list and I could use it as needed. you're right, the IDE recognizes classes in the SAME namespace.

One thing that cheats new users is that namespaces are not inherited. If you have a namespace MyProject and a different namespace MyProject.SubNamespace, the compiler will not automatically bind SubNamespacetwo. You need to specify a Using statement, eg. "Using MyProject.SubNamespace" to allow the IDE to use classes in this namespace.

0


source







All Articles