473,398 Members | 2,165 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,398 software developers and data experts.

#define on multiple files

Hello all,

I'm quite new to C# (< 6 months) but really love it and is my language of
choice ..... but I have one question I've not been able to find out .....

In C++ a #define label in one file can be referanced in other *.cpp files,
however in C# if I have say #define SPEED it only refers to the class(es)
in that *.cs file.

Is there anyway to have one #define label work with multiple *.cs files?

Thank you for your time,

David
Nov 17 '05 #1
6 9163
Hi,

Define it in the project level, in the project properties / Configuration
properties / build / Conditional compilation constants

One problem I have faced is that you cannot define a symbol solution wide, I
would like to have that feature implemented sometimes in the future.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"David Young" <Da**********@btinternet.com> wrote in message
news:d5**********@vins1.reading.ac.uk...
Hello all,

I'm quite new to C# (< 6 months) but really love it and is my language of
choice ..... but I have one question I've not been able to find out .....

In C++ a #define label in one file can be referanced in other *.cpp files,
however in C# if I have say #define SPEED it only refers to the class(es)
in that *.cs file.

Is there anyway to have one #define label work with multiple *.cs files?

Thank you for your time,

David

Nov 17 '05 #2
Cheers Ignacio, that's the trick!!!!

David

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:un*************@TK2MSFTNGP12.phx.gbl...
Hi,

Define it in the project level, in the project properties / Configuration
properties / build / Conditional compilation constants

One problem I have faced is that you cannot define a symbol solution wide, I would like to have that feature implemented sometimes in the future.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"David Young" <Da**********@btinternet.com> wrote in message
news:d5**********@vins1.reading.ac.uk...
Hello all,

I'm quite new to C# (< 6 months) but really love it and is my language of choice ..... but I have one question I've not been able to find out ......
In C++ a #define label in one file can be referanced in other *.cpp files, however in C# if I have say #define SPEED it only refers to the class(es) in that *.cs file.

Is there anyway to have one #define label work with multiple *.cs files?

Thank you for your time,

David


Nov 17 '05 #3
Why do you want a #define at all? #defines cause as many problems as
they solve, which is why their functionality is reduced in C# (and they are
working on reducing it in C++)

My guess is that you have some code like the following:

#if SPEED
// fast way of doing something
#else
// slow/careful way of doing that thing.
#endif

IF so, then you should note that if you have a class like:

class Configuration
{
public const bool Speed = true;
}

then you can write code like this:

if (Configuration.Speed)
{
// fast way of doing something
}
else
{
// slow/careful way of doing that thing.
}
This will be compiled PRECISELY the way the top code way, with code
being generated just the "true" portion of the if(). (This is a requirement
of the C# language)
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"David Young" <Da**********@btinternet.com> wrote in message
news:d5**********@vins1.reading.ac.uk...
I'm quite new to C# (< 6 months) but really love it and is my language of
choice ..... but I have one question I've not been able to find out .....

In C++ a #define label in one file can be referanced in other *.cpp files,
however in C# if I have say #define SPEED it only refers to the class(es)
in that *.cs file.

Is there anyway to have one #define label work with multiple *.cs files?

Nov 17 '05 #4
Fully agree with you, but I need a "global" switch where I can change in one
place rather than going through many *.cs files setting the bool flag on
each class (and possibly missing the odd one!)

David
"James Curran" <ja*********@mvps.org> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
Why do you want a #define at all? #defines cause as many problems as
they solve, which is why their functionality is reduced in C# (and they are working on reducing it in C++)

My guess is that you have some code like the following:

#if SPEED
// fast way of doing something
#else
// slow/careful way of doing that thing.
#endif

IF so, then you should note that if you have a class like:

class Configuration
{
public const bool Speed = true;
}

then you can write code like this:

if (Configuration.Speed)
{
// fast way of doing something
}
else
{
// slow/careful way of doing that thing.
}
This will be compiled PRECISELY the way the top code way, with code
being generated just the "true" portion of the if(). (This is a requirement of the C# language)
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"David Young" <Da**********@btinternet.com> wrote in message
news:d5**********@vins1.reading.ac.uk...
I'm quite new to C# (< 6 months) but really love it and is my language of choice ..... but I have one question I've not been able to find out ......
In C++ a #define label in one file can be referanced in other *.cpp files, however in C# if I have say #define SPEED it only refers to the class(es) in that *.cs file.

Is there anyway to have one #define label work with multiple *.cs files?


Nov 17 '05 #5
Look again at my code.

You change it once (in the Configuration class ), and it is global
throughout your code.

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"David Young" <Da**********@btinternet.com> wrote in message
news:d5*********@vins1.reading.ac.uk...
Fully agree with you, but I need a "global" switch where I can change in one place rather than going through many *.cs files setting the bool flag on
each class (and possibly missing the odd one!)

David
"James Curran" <ja*********@mvps.org> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
Why do you want a #define at all? #defines cause as many problems as
they solve, which is why their functionality is reduced in C# (and they

are
working on reducing it in C++)

My guess is that you have some code like the following:

#if SPEED
// fast way of doing something
#else
// slow/careful way of doing that thing.
#endif

IF so, then you should note that if you have a class like:

class Configuration
{
public const bool Speed = true;
}

then you can write code like this:

if (Configuration.Speed)
{
// fast way of doing something
}
else
{
// slow/careful way of doing that thing.
}
This will be compiled PRECISELY the way the top code way, with code
being generated just the "true" portion of the if(). (This is a

requirement
of the C# language)
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"David Young" <Da**********@btinternet.com> wrote in message
news:d5**********@vins1.reading.ac.uk...
I'm quite new to C# (< 6 months) but really love it and is my language of choice ..... but I have one question I've not been able to find out .....
In C++ a #define label in one file can be referanced in other *.cpp files, however in C# if I have say #define SPEED it only refers to the class(es) in that *.cs file.

Is there anyway to have one #define label work with multiple *.cs

files?


Nov 17 '05 #6
James Curran <ja*********@mvps.org> wrote:

<snip>
This will be compiled PRECISELY the way the top code way, with code
being generated just the "true" portion of the if(). (This is a requirement
of the C# language)


It's not quite the same though - the code which doesn't actually get
put in the assembly still needs to be valid C#, whereas with a #if it
doesn't. I agree that most of the time that isn't a problem, but in
some cases it might be (for instance, if you want to be able to
conditionally compile against code which doesn't exist in a certain
configuration).

It also doesn't work for things like #if-ing attributes, which can be
handy sometimes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of...
3
by: prettysmurfed | last post by:
Hi all I have this, probably stupid question, how to avoid multiple definitions when a header file is included more than once. I thought, when you wrote the header-file and used the...
4
by: Rafi Kfir | last post by:
"Hi, This is a very simple question that confuses me (probably due to some lack of knowledge...) I will illustrate my problem with a smiple example: My project has the following files:
12
by: Riley DeWiley | last post by:
I am looking for a graceful way to declare a string const that is to be visible across many files. If I do this: //----hdr.h const char * sFoo = "foo"; //file.cpp
1
by: Richard A. Lowe | last post by:
I'm new to hand-coding XSD files - how can I indicate that I want to reference tags from another XSD document in a certain section of my XSD? Essentially, I want to define one XSD with some...
1
by: Hans De Schrijver | last post by:
I'm new to C# development, so here's a basic question. I'm developing a code library (no UI) where several of the classes will implement an IPersistable interface. Each class lives in its own...
4
by: yancheng.cheok | last post by:
Recently, I try to replace #define with const in header file. However, there are concerns on, multiple const object will be created, if the header file is included in multiple cpp files. For...
14
by: raghu | last post by:
Hello I have a doubt plz clarify that #ifndef SYSTEM_H #define SYSTEM_H what will be the value of SYATEM_H after this #define statement and before that statement. Thanking you all Bye
11
by: Sachin Garg | last post by:
I need to build two executables from my code, one having all the code (and thus application features) and other not having it all. How to best manage the code that shouldn't go in one of the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.