I am trying to add a character to a char array but I receive a NullReferenceException
when doing so. My code is as follows:
string[] triples = new string[10];
for(int i = 0; i < triples.Length; i += 3) {
triples[i] = bits.Substring(i, 3);
}
char[] corrected = new char[triples.Length];
for(int i = 0; i < triples.Length; i++) {
int zero = 0;
int one = 0;
foreach(char j in triples[i]) {
if(j == '0') {
zero += 1;
} else {
one += 1;
}
}
if(zero > one) {
corrected[i] = '0';
} else {
corrected[i] = '1';
}
}
The issue arises on the corrected[i] = '0';
lines.
bits
is a String
I have looked at this question, especially the section on arrays but I cannot find a solution