Any substitutes for #include in C#?

Any substitutes for #include in C#?

am 20.07.2005 16:40:02 von byron

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.

Re: Any substitutes for #include in C#?

am 20.07.2005 17:01:42 von Peter van der Goes

"Byron" wrote in message
news:DF81EC22-F352-4165-85BD-117914634341@microsoft.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.

RE: Any substitutes for #include in C#?

am 20.07.2005 18:58:03 von AMercer

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.

RE: Any substitutes for #include in C#?

am 22.07.2005 18:30:01 von alanrn

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.