473,468 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5337
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.