473,246 Members | 1,433 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

Sharing classes (.cs) between multiple projects

Hi !

What is the common use of sharing a single .cs across multiple project
files ?

I think it's to share common classes between projects.
I have actually a .cs file shared accross multiple projects in a same
solution. It's nice to have a common "set" of Classes.

Is this the only way to share classes between projects ?

Are there any side effects to do this ?
I have also found a bug within the ClassViewer :
If I have 2 project and i'm opening the classviewer to view the class
headers from the common .cs file, when I change a class header (or
method) from the common.cs file, only one project reflects in realtime
the changes made in the source code.
Did you experience the same problem ?
Regards,
Cybertof.
Nov 16 '05 #1
5 5326
cybertof <cy****************@gmx.net> wrote:
What is the common use of sharing a single .cs across multiple project
files ?

I think it's to share common classes between projects.


No - it's much better to put everything you want to share into a class
library project which is referenced by other projects. That way you
only get the type defined once, so you won't run into nasty problems
with TypeCastExceptions, you use less memory, you don't run into issues
of the different types being initialized twice, etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Does a class-library needs to be compiled to be used by other projects ?

In fact, I don't understand what is the difference between a "class-
library" as you name it, and a shared .cs file containing classes
definition to be shared.

When you say "use less memory", what do you mean ?
If i don't instantiate a class from my .cs shared file, i don't use
other not-usefull classes either.

But I'm ready to use class-libraries if it's the good way to do it.
I would like to understrand a little bit more about this.

In article <MP************************@msnews.microsoft.com >,
sk***@pobox.com says...
cybertof <cy****************@gmx.net> wrote:
What is the common use of sharing a single .cs across multiple project
files ?

I think it's to share common classes between projects.


No - it's much better to put everything you want to share into a class
library project which is referenced by other projects. That way you
only get the type defined once, so you won't run into nasty problems
with TypeCastExceptions, you use less memory, you don't run into issues
of the different types being initialized twice, etc.

Nov 16 '05 #3
cybertof <cy****************@gmx.net> wrote:
Does a class-library needs to be compiled to be used by other projects ?
Yes.
In fact, I don't understand what is the difference between a "class-
library" as you name it, and a shared .cs file containing classes
definition to be shared.
The difference is that a class library will only end up with the type
in one assembly (the library), and be *used* by other projects.
When you say "use less memory", what do you mean ?
If i don't instantiate a class from my .cs shared file, i don't use
other not-usefull classes either.
I'm not talking about instantiation - I'm talking about the memory for
the type itself, and any static variables etc.
But I'm ready to use class-libraries if it's the good way to do it.
I would like to understrand a little bit more about this.


Have you never used a class library before?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
No...
In article <MP************************@msnews.microsoft.com >,
sk***@pobox.com says...

Have you never used a class library before?

Nov 16 '05 #5
cybertof <cy****************@gmx.net> wrote:
No...


Well, thinking about it, you have *used* a class library, for certain -
you do every time you use the .NET framework at all. It's just you
haven't created your own one :)

In the solution, create a new project of type "Class Library". Add
whatever shared classes you want there.

Then in the other projects, add a reference to that project - bingo,
you'll be able to use the shared classes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: cybertof | last post by:
Hi ! What is the common use of sharing a single .cs across multiple project files ? I think it's to share common classes between projects. I have actually a .cs file shared accross multiple...
3
by: Harry Whitehouse | last post by:
I'm developing a small class which will be used in a number of distinct C# projects. This small class is undergoing constant change/refinement as I try to employ it in the different projects. ...
5
by: Tinius | last post by:
I have created a class which I wish to reuse amongst several projects. But each time I Add the class to a new project, it creates a copy of that class in the folder of the new project. This means...
1
by: JoeS | last post by:
Is there anyway to share a single pch file between projects in VC 7.0? I have 300+ projects each of which creates its own pch. All projects include the exact same header files in the precompiled...
16
by: Robert W. | last post by:
I'm building a solution that has 1 component for the Desktop and 1 component for the Pocket PC. (Though this isn't a mobile question). I have a data library that will be shared on both platforms....
3
by: Shikari Shambu | last post by:
Hi All, I have a situation where multiple applications are sharing some pages/ controls. So, I have a separate common project that has the common pages/ controls. My question is how do I...
0
by: rcolby | last post by:
Hi, A little advice on code sharing across projects, namespaces and dll's for references. I've got an application that is split between three different projects (one for a service, one for...
1
by: Joe | last post by:
While I understand that Server Side Includes still work, I realize it's not the best practice for sharing code such as a common set of includes between screens. In ASP.NET I've already built...
2
by: Jeff Dege | last post by:
I'm working with a group that's been doing C++ coding for quite a long time, now, and in that environment we've pretty much worked out development practices that serve us well. We've been doing...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.