Click here to Skip to main content
15,910,083 members
Home / Discussions / C#
   

C#

 
GeneralChanging Background Image of form Pin
cheech522516-Nov-04 11:53
cheech522516-Nov-04 11:53 
GeneralRe: Changing Background Image of form Pin
Nick Parker16-Nov-04 12:37
protectorNick Parker16-Nov-04 12:37 
GeneralEfficiently Swapping 2 numbers! Pin
jdeakin200416-Nov-04 11:51
jdeakin200416-Nov-04 11:51 
GeneralRe: Efficiently Swapping 2 numbers! Pin
latta16-Nov-04 12:37
latta16-Nov-04 12:37 
GeneralRe: Efficiently Swapping 2 numbers! Pin
Nick Parker16-Nov-04 12:40
protectorNick Parker16-Nov-04 12:40 
GeneralRe: Efficiently Swapping 2 numbers! Pin
latta16-Nov-04 12:58
latta16-Nov-04 12:58 
GeneralRe: Efficiently Swapping 2 numbers! Pin
Skynyrd16-Nov-04 13:22
Skynyrd16-Nov-04 13:22 
GeneralRe: Efficiently Swapping 2 numbers! Pin
Dennis C. Dietrich16-Nov-04 13:22
Dennis C. Dietrich16-Nov-04 13:22 
jdeakin2004 wrote:
i noticed in a few articles people have had to swap 2 numbers of which a couple went to a ellaborate means to do so.

Were the source codes in those articles actually written in C# or in C/C++? In case it was C# I'm not sure if it makes a notable difference. Your suggestion compiles to:
IL_0000:  ldc.i4.1
IL_0001:  stloc.0
IL_0002:  ldc.i4.2
IL_0003:  stloc.1
IL_0004:  ldloc.1
IL_0005:  ldloc.0
IL_0006:  xor
IL_0007:  stloc.0
IL_0008:  ldloc.0
IL_0009:  ldloc.1
IL_000a:  xor
IL_000b:  stloc.1
IL_000c:  ldloc.1
IL_000d:  ldloc.0
IL_000e:  xor
IL_000f:  stloc.0
IL_0010:  ret

Whereas the simpler approach of using three variables compiles to:
IL_0000:  ldc.i4.1
IL_0001:  stloc.0
IL_0002:  ldc.i4.2
IL_0003:  stloc.1
IL_0004:  ldc.i4.0
IL_0005:  stloc.2
IL_0006:  ldloc.0
IL_0007:  stloc.2
IL_0008:  ldloc.1
IL_0009:  stloc.0
IL_000a:  ldloc.2
IL_000b:  stloc.1
IL_000c:  ret

The second example is four IL opcodes shorter and doesn't need the xor operator. Altogether no really big difference and more important I'd say you still won't know which one executes faster unless you specify the native code compiler and the target platform. Personally I might prefer the solution with three variables. Somehow I find it to be more readable. Anyway, if I consider efficiency with every line of code I write I might also go back to C and inline assembler. C# and .NET are about RAD. If it isn't fast enough maybe it's the wrong tool for the job.

Best regards
Dennis
Generalfile association Pin
bwagz16-Nov-04 11:23
bwagz16-Nov-04 11:23 
GeneralRe: file association Pin
Nick Parker16-Nov-04 11:32
protectorNick Parker16-Nov-04 11:32 
Generalupdate statement Pin
cmarmr16-Nov-04 10:33
cmarmr16-Nov-04 10:33 
GeneralRe: update statement Pin
Nick Parker16-Nov-04 11:23
protectorNick Parker16-Nov-04 11:23 
GeneralRe: update statement Pin
Luis Alonso Ramos16-Nov-04 11:27
Luis Alonso Ramos16-Nov-04 11:27 
GeneralRegular expression problem Pin
Christian Graus16-Nov-04 9:03
protectorChristian Graus16-Nov-04 9:03 
GeneralRe: Regular expression problem Pin
Daniel Turini16-Nov-04 9:11
Daniel Turini16-Nov-04 9:11 
GeneralRe: Regular expression problem Pin
Christian Graus16-Nov-04 9:43
protectorChristian Graus16-Nov-04 9:43 
GeneralRe: Regular expression problem Pin
Nick Parker16-Nov-04 11:16
protectorNick Parker16-Nov-04 11:16 
GeneralRe: Regular expression problem Pin
Christian Graus16-Nov-04 13:26
protectorChristian Graus16-Nov-04 13:26 
GeneralPlease help in richTextbox ..!!! Pin
MohamedShehab16-Nov-04 7:03
MohamedShehab16-Nov-04 7:03 
GeneralRe: Please help in richTextbox ..!!! Pin
Judah Gabriel Himango16-Nov-04 9:04
sponsorJudah Gabriel Himango16-Nov-04 9:04 
GeneralRe: Please help in richTextbox ..!!! Pin
Nick Parker16-Nov-04 11:26
protectorNick Parker16-Nov-04 11:26 
Generalconverting .cpp source to .cs source Pin
Blubbo16-Nov-04 6:34
Blubbo16-Nov-04 6:34 
GeneralRe: converting .cpp source to .cs source Pin
Nick Parker16-Nov-04 6:58
protectorNick Parker16-Nov-04 6:58 
GeneralRe: converting .cpp source to .cs source Pin
..Hubert..16-Nov-04 21:49
..Hubert..16-Nov-04 21:49 
GeneralSending Keys Pin
Anonymous16-Nov-04 6:28
Anonymous16-Nov-04 6:28 

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.