C# Jagged Array check if value exists/true -
this code , using 2 dimension array .
top = 0; if(rowcol[i-1][j]){ top = rowcol[i-1][j] }
but shows error :
cannot implicitly convert type 'string' 'bool'
full code :
string[] filedata = file.readalllines(@"c:\users\apr13mpsip\desktop\oneorganizer\oneorganizer\wordpuzzle\testing.txt"); string[] linevalues; int row = 0; int col; string[][] rowcol = new string[filedata.length][]; foreach (string line in filedata) { linevalues = line.split(new string[] { "," }, stringsplitoptions.none); rowcol[row] = new string[linevalues.length]; col = 0; foreach (string value in linevalues) { rowcol[row][col] = value; col++; } row++; } (int = 0; < rowcol.getlength(0) ; i++) { (int j = 0; j < rowcol[i].getlength(0) ; j++) { int iadd = i+1 <rowcol.getlength(0) ? + 1: 0; int iminus = i-1> 0 ? - 1 : 0; int jadd = j+1 <rowcol.getlength(0) ? j + 1 : 0; int jminus = j-1 > 0 ? j - 1 : 0; var self = rowcol[i][j]; // current value top = 0; if(rowcol[iminus][j]){ top = rowcol[iminus][j] } // error here } }
i reading textfile , creating out of creating rows , cols 10x10 in jagged array. find value rowcol[][] .
because
if(rowcol[i-1][j])
will return string per definition
string[][] rowcol
and if statement needs bool. need check against like
if(rowcol[i-1][j] == "stringtotest")
Comments
Post a Comment