473,385 Members | 1,464 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,385 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 5323

"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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.