# How to get the previous value from string array c#(Unity)

I have this example data

Data: P ,B ,B ,T ,P

This must be something like this

But what is happening to me is this

here's my code

string[,] table = new string[104, 6];
string newPreviousValue = "placeholder";
int xIndex = -1;
int yIndex = 0;
if (result.Equals(newPreviousValue) &&  yIndex < table.GetLength(1) - 1)
{
yIndex += 1;
table[xIndex, yIndex] = result;
}

else
{
xIndex += 1;
yIndex = 0;
table[xIndex, yIndex] = result;
}


So you won't get confuse the result variable is the data generator. What could be missing on my condition?

I tried doing something like this

if (result.Equals(newPreviousValue) && result.Equals(newPreviousValueTie) && yIndex < table.GetLength(1) - 1) but what's happening here is they're all in y axis falling in line .

• What's the rule that determines when something can stack in the same column as a dissimilar entry (Tie stacking on Banker) versus when it can't? May 11 '18 at 12:16
• what could possibly the remedy with this @DMGregory May 12 '18 at 2:23
• I don't know because you haven't answered the question I asked you above. May 12 '18 at 11:42
• As what said @DMGregory it will not move from X axis. May 15 '18 at 2:55

So you mean every tie must not move to X axis ? If that's the case you can do it something like this :

Inside of your

if (result.Equals(newPreviousValue) &&  yIndex < table.GetLength(1) - 1)
{
yIndex += 1;
table[xIndex, yIndex] = result;
}


You recode like this

if (result.Equals(newPreviousValue) &&  yIndex < table.GetLength(1) - 1)
{
var newResult = previousValue.Contains(scoreboardWinner[2]);
if (newResult == previousValue.Contains(scoreboardWinner[2]))
{
yIndex += 1;
table[xIndex, yIndex] = result;
}
else
{
yIndex += 1;
table[xIndex, yIndex] = result;
}
}


Maybe that will do.

• Hmm i didn't think of that . I'll try this one sir when i get home . Thank you May 15 '18 at 2:52
• Please don't "sir" me . If that's what you want on your rule then I am pretty sure that is the answer May 15 '18 at 2:53