0
I have a question a specific part on this two dimensional area
Please explain this specific part of array Console.WriteLine("a[{0},{1}] = {2}", i, j, a[i,j]) https://code.sololearn.com/cKn1t7h5woyI/?ref=app
14 Answers
+ 1
No. Thats just one charecter displayed as it is in the output... See that replacing by that with any other charecter..
And
Check by replacing this for observation:
Console.WriteLine("A{0}", i);
+ 1
Your 2d array is
j=0. j=1
i=0 0 0
i=1. 1 2
i=2 2 4
i=3 3 6
i=4 4 8
Now see, what not you understanding..?
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
/* an array with 5 rows and 2 columns*/
int[,] a = new int[5, 2] {{0,0}, {1,2},
{2,4}, {3,6}, {4,8} };
int i, j;
/* output each array element's value */
for (i = 0; i < 5; i++)
{
for (j = 0; j < 2; j++)
{
Console.WriteLine("a[{0},{1}] = {2}",
i, j,a[i,j]);
}
}
Console.ReadKey();
}
}
}
/* I am trying to understand this part specifically.
Console.WriteLine("a[{0},{1}] = {2}", i, j, a[i,j])
*/
0
Console.WriteLine("a[{0},{1}] = {2}",
i, j,a[i,j]);
{0} is replaced by 0th (first) argument's value after the string argument in output string..
Here {0} by i value...
{1} by next arguments value, here by j value..
{2} by next arguments value, here by a[i, j]..
This continues, if any further there..
0
I guess I don't understand what the = sign is doing here. Is it that = sign is assign the value of {2} to a[i,j} ?
Thanks
0
Thanks still trying to figure it out but getting close. When I replace the code with
Console.WriteLine("A{0}", i);
the output is
A0
A0
A1
A1
A2
A2
A3
A3
A4
A4
0
Why is the there double number shown like?
A0
A0
A1
A1
etc
0
Iam taking about, only observe the specific line.. In output.. There inner loop, I value not changing.. J value changes from 0 to 2-1.. And outputing I value not j,.. Replace I with J, then see..
Or check that extra example, I said in only one separate loop
0
making more sense so for example in the inner for loop.
for (j = 0; j < 2; j++)
it executes
first iteration at 0
second iteration at 1
third iteration at 2 which is not greater than 2 so the loop stops. That is why there is
A0
A0
A1
A1
A2
A2
etc
0
Still figuring it out though how the = {2} is outputting 0
The first line on the output is
a[0,0] = 0 for example.
I understand the a[0,0] output perfectly
0
Yes.. But now your doubt changed to loop from concole..!!!!!
0
I think I got it now, working through the last of the logic.
0
I got thanks. Breaking down like that made the difference thanks
0
Thanks for your help yesterday.
Jayakrishna🇮🇳