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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -