doubt in c# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

doubt in c#

static void Main(string[] args) { int x = 10; double y = 20; Console.WriteLine("x = {0}; y = {1}", x, y); } // Output: x = 10; y = 20 but when i code like this Console.WriteLine("x = {3}; y = {4}", x, y); codeplay ground compiler reports error ,why is it so??.Where you say any place holder can be used.

10th May 2020, 12:31 PM
Dhananjay Satish Kupekar
Dhananjay Satish Kupekar - avatar
1 Answer
+ 2
{0} --> here the first variable after the string (in Console.WriteLine) will be inserted, which is x Correspondingly, {1} refers to y. {3} and {4} don't work because they refer to nothing
10th May 2020, 5:54 PM
Lisa
Lisa - avatar