469,299 Members | 2,079 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

Any substitutes for #include in C#?

I'm working of several projects that use many of the same constants and I
wanted to put them all into a single file and include them in all the
projects that need them so I can maintain them in one place. I assume C# has
some mechanism similar to the #include since it's so handy. Do you just
create a class that contains the definitions outside the projects in a common
structure then include the class in all the projects?

Any suggestions would be greatly appreciated.
Jul 22 '05 #1
3 5185

"Byron" <By***@discussions.microsoft.com> wrote in message
news:DF**********************************@microsof t.com...
I'm working of several projects that use many of the same constants and I
wanted to put them all into a single file and include them in all the
projects that need them so I can maintain them in one place. I assume C#
has
some mechanism similar to the #include since it's so handy. Do you just
create a class that contains the definitions outside the projects in a
common
structure then include the class in all the projects?

Any suggestions would be greatly appreciated.


One way to accomplish what you want is to place your reusable stuff in a
class library, then in projects that need it, add a reference to the
library.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Jul 22 '05 #2
You can include a source file in multiple projects by doing:
Project
Add Existing Item
browse to the file and select it
instead of doing Open, click the small arrow near it and click Link File

"Byron" wrote:
I'm working of several projects that use many of the same constants and I
wanted to put them all into a single file and include them in all the
projects that need them so I can maintain them in one place. I assume C# has
some mechanism similar to the #include since it's so handy. Do you just
create a class that contains the definitions outside the projects in a common
structure then include the class in all the projects?

Any suggestions would be greatly appreciated.

Jul 22 '05 #3
As a C/C++ programmer turned C# programmer I had the same question. One
think that I have often seen is to create a class named Globals (filename
Globals.cs) and put the information you're talking about in that class. You
could subsequently "compile" it into a class library if it's used in multiple
apps, or you could simply include it somewhere in your project.

After having seen this method used a couple of times, I came across
information endorsing this in a recently-published (March '05) book entitled
"Practical Guidelines and Best Practices for Microsoft Visual Basic and
Visual C# Developers." The following is a quote from the book:

"Use Globals for the type that contains all the global variables of the
current application. Global variables are implemented as static fields of
this type....

"Why: References to those variables are in the form Globals.VariableName and
are therefore more readable and easier to spot."

..ARN.
"Byron" wrote:
I'm working of several projects that use many of the same constants and I
wanted to put them all into a single file and include them in all the
projects that need them so I can maintain them in one place. I assume C# has
some mechanism similar to the #include since it's so handy. Do you just
create a class that contains the definitions outside the projects in a common
structure then include the class in all the projects?

Any suggestions would be greatly appreciated.

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by steve | last post: by
60 posts views Thread by Derrick Coetzee | last post: by
9 posts views Thread by zolli | last post: by
5 posts views Thread by David Mathog | last post: by
1 post views Thread by ya man | last post: by
3 posts views Thread by Byron | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.