Q:

Index is outside the bounds of the array

i have this code:
String Oddelovac = textBox1.Text;                                     
string file = openFileDialog1.FileName;
foreach (String line in File. ReadAllLines(file).Skip(radek))
{
    String[] columns = line. Split(Oddelovac. ToCharArray());
    Mnozstvi = columns[poradi_mnozstvi];
    Prod_cena = columns[poradi_ProdCena];
    Ean = columns[poradi_Ean];
    Cislo = columns[poradi_Cislo];
    Nazev = columns[poradi_Nazev];
    Dan = columns[poradi_Dan];
    ng_Doklad = columns[poradi_NG];
    o1 = columns[poradi_o1];
    o2 = columns[poradi_o2];
    zc = columns[poradi_ZC];
    u1 = columns[poradi_U1];
    Od = columns[poradi_Od];
    MJ = columns[poradi_MJ];
    datum_nahrani = System. DateTime. Now. ToShortDateString();
}

I have this error:
index is outside the bounds of the array   - in cast zc = columns[poradi_ZC];
The error is in poradi_ZC, it have 2 digit...
Example:
poradi_o1=8
poradi_o2=9
poradi_ZC=10

Have you any ideas? 

A:

A basic "fix" is to only try to get a value if the array you are fetching from is long enough: 
zc = (columns. Length > poradi_ZC) ?  columns.[poradi_ZC] : string. Empty;

...but you have to decide if that makes sense in your case, or if something else is wrong.  In any case, that is the reason for your error (columns contains less than poradi_ZC + 1 elements). 
(Remember that array indexes start with 0, so the second element is found with columns[1], and the last with columns[nrOfItems - 1]).