Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello I have the following piece of code,

C#
Console.WriteLine("YES Found SyncMode5");
int myValue = (int) subkey1.GetValue("SyncMode5");
Console.WriteLine("miValor: ", myValue);
Console.WriteLine(myValue);

And the following is the output

Windows 7 Professional
YES Found SyncMode5
miValor:
2

Questions
1. Why miValor: does not output the number 2 ?
2. Why Console.WriteLine(myValue) it does output the number 2?

I would like to show the number 2 next to miValor.
Thanks 4 ur help,
G
Posted

1 solution

C#
Console.WriteLine("YES Found SyncMode5");
int myValue = (int) subkey1.GetValue("SyncMode5");
Console.WriteLine("miValor: {0}", myValue);


Do you see the difference?

Regards,

Manfred
 
Share this answer
 
Comments
namerg 22-Feb-13 18:24pm    
Manfred,
You got it. Can you explain me why the {0} ?
I am new with C#, I do understand {0} as an array.
Thanks for your help.
Garth J Lancaster 22-Feb-13 18:29pm    
no - in this case {0} IS NOT an array - its a 'placeholder' for a variable to be inserted into the output
Sergey Alexandrovich Kryukov 22-Feb-13 18:25pm    
Captain Obvious to help: there is a difference! My 5. :-)
—SA
namerg 22-Feb-13 18:34pm    
Thank you guys. You solved my issue and questions.
I got the desired result through this:
Console.WriteLine("Current CHECK FOR NEWER VERSIONS OF STORED PAGES value: {0} {1} Eveytime I start IE", myValue, myValue);
Matt T Heffron 22-Feb-13 21:03pm    
If you're going to output the same value more than once in a given Console.WriteLine, then you don't need it multiple times in the arguments. Unlike c & c++, the {n} (where n is an integer >= 0) can be used multiple times to reference the same positional argument:
Console.WriteLine("Current CHECK FOR NEWER VERSIONS OF STORED PAGES value: {0} {0} Eveytime I start IE", myValue);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900