c# - Array element is maybe not set -
in method below set string smdrext tmp[3]. however, tmp[3] seems empty because "index outside bounds of array.". before set it, can change exist make sure program not halt again due this?
public void writetocsv(string line, string path) { string[] tmp = line.split(','); string smdrext = tmp[3]; if (ext.contains(convert.tostring(smdrext))) { file.appendalltext(path, line + "\n"); } }
please try below code snippet.
public void writetocsv(string line, string path) { if (!string.isnullorempty(line)) { string[] tmp = line.split(','); if (tmp.length > 3) { string smdrext = tmp[3]; if (ext.contains(convert.tostring(smdrext))) { file.appendalltext(path, line + "\n"); } } } }
let me know if concern.
Comments
Post a Comment