472,374 Members | 1,156 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 5271

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
2
by: Jinghao | last post by:
Hi, During my research work, I need to call my own functions instead of calling the runtime function "fixup()" and the internal function "_dl_lookup_symbol()" in libc.so. As I know, the...
9
by: zolli | last post by:
Hi, I've been banging my head against this for a while now. Hoping someone here can shed some light on what's going on. On including stdlib.h in a file, I'm seeing the following errors: ...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
1
by: ya man | last post by:
when i use #include <iostream.h> in some files i get lots of error messages of the kind 'ambiguous symbol this is solved when i use #include <iostream why is that ? and can i use #include...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
3
by: Byron | last post by:
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.