Click here to Skip to main content
15,922,630 members
Home / Discussions / C#
   

C#

 
AnswerRe: Depth first search Pin
shdelpiero26-May-06 3:21
shdelpiero26-May-06 3:21 
QuestionActive Directory 2003 Pin
AnhTin25-May-06 21:41
AnhTin25-May-06 21:41 
QuestionData binding.. is it possible ? Pin
Imtiaz Murtaza25-May-06 20:25
Imtiaz Murtaza25-May-06 20:25 
Questionusing #define to define string constants [modified] Pin
abhijit pai25-May-06 20:20
abhijit pai25-May-06 20:20 
AnswerRe: using #define to define string constants [modified] Pin
Colin Angus Mackay25-May-06 23:13
Colin Angus Mackay25-May-06 23:13 
GeneralRe: using #define to define string constants [modified] Pin
abhijit pai25-May-06 23:33
abhijit pai25-May-06 23:33 
GeneralRe: using #define to define string constants [modified] Pin
Larantz26-May-06 0:24
Larantz26-May-06 0:24 
GeneralRe: using #define to define string constants [modified] Pin
Colin Angus Mackay26-May-06 11:15
Colin Angus Mackay26-May-06 11:15 
abhijit pai wrote:
I do not undersatand how it is a strength.
Can you please kindly explain?


It is a strength because it forces you to use proper language constructs and to put strings and other values in to consts

For example in C++ you could put
#define MY_STRING "my_string"
SomeFunction(MY_STRING);


or worse

#define MY_INT 5+5
SomeFunction(MY_INT*MY_INT);

which expands out to SomeFunction(5+5*5+5); which is equivalent to SomeFunction(35); and not SomeFunction(100); which some might be expected.

in C# you put
const MY_STRING = "my_string";
or
const MY_INT = 5+5;

When you call SomeFunction(MY_INT*MY_INT) you get a value that makes sense.

using consts in C# is also type safe. So the compiler can show you easily what the problem is, if there is one. Preprocessor statements like #define are naturally evaluated before the compiler runs. This means that in C++ the defined values are expanded out in advance. If the compiler has a problem with some code it can only show you the expanded version, which may look quite different to the version you see in the IDE, since it never sees the version you see.

Does this help?


"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)

My: Website | Blog
GeneralRe: using #define to define string constants [modified] Pin
abhijit pai29-May-06 3:36
abhijit pai29-May-06 3:36 
GeneralRe: using #define to define string constants [modified] Pin
Colin Angus Mackay29-May-06 4:49
Colin Angus Mackay29-May-06 4:49 
QuestionHow to monitor files created by perticular process in c# [modified] Pin
HirenSuchak25-May-06 19:50
HirenSuchak25-May-06 19:50 
QuestionGet the active sqlserver names Pin
Shiv525-May-06 19:16
Shiv525-May-06 19:16 
Questionread specific line Pin
the pink jedi25-May-06 15:06
the pink jedi25-May-06 15:06 
AnswerRe: read specific line Pin
Christian Graus25-May-06 15:29
protectorChristian Graus25-May-06 15:29 
QuestionHow to Create self-extract with password protected ? Pin
hdv21225-May-06 12:52
hdv21225-May-06 12:52 
Questionhow can i get the output variable from .. Pin
alokabasha25-May-06 12:50
alokabasha25-May-06 12:50 
AnswerRe: how can i get the output variable from .. Pin
Judah Gabriel Himango25-May-06 13:48
sponsorJudah Gabriel Himango25-May-06 13:48 
AnswerRe: how can i get the output variable from .. Pin
Judah Gabriel Himango25-May-06 13:51
sponsorJudah Gabriel Himango25-May-06 13:51 
Questionplz help! Pin
maryamf25-May-06 12:22
maryamf25-May-06 12:22 
AnswerRe: plz help! Pin
Saqib Mehmood25-May-06 18:24
Saqib Mehmood25-May-06 18:24 
QuestionGlobal Hotkey And Keyboard Hook Problem Pin
Draders2325-May-06 11:44
Draders2325-May-06 11:44 
QuestionAccess violation in mscorwks.dll Pin
asbasir25-May-06 11:35
asbasir25-May-06 11:35 
QuestionHow to append bitmap data to an existing bitmap? Pin
zenzero25-May-06 10:23
zenzero25-May-06 10:23 
AnswerRe: How to append bitmap data to an existing bitmap? Pin
Guffa25-May-06 11:27
Guffa25-May-06 11:27 
GeneralRe: How to append bitmap data to an existing bitmap? Pin
zenzero25-May-06 11:45
zenzero25-May-06 11:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.