Click here to Skip to main content
11,411,494 members (65,705 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hello I have the following piece of code,

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 22-Feb-13 12:44pm
namerg408

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

Do you see the difference?

Regards,

Manfred
  Permalink  
Comments
namerg at 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 at 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 at 22-Feb-13 18:25pm
   
Captain Obvious to help: there is a difference! My 5. :-)
—SA
namerg at 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 at 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)

  Print Answers RSS
0 OriginalGriff 223
1 Sascha Lefévre 155
2 Sergey Alexandrovich Kryukov 149
3 ProgramFOX 90
4 Dave Kreskowiak 90
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 7,128
2 Maciej Los 3,440
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web02 | 2.8.150414.5 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100