-1
string date = dr["event_date"].ToString();
string[] eventdate = date.Split('-');
int date_no = Convert.ToInt32(eventdate[2]);

I get an error

Index was outside the bounds of the array

on the last line

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jawad
  • 39
  • 1
  • 5

1 Answers1

-1
int date_no = Convert.ToInt32(eventdate[1])

Array index starts from 0

Raj
  • 664
  • 7
  • 23
  • 3
    Not the one who down-voted you, but people tend to down-vote "lazy" answers. Your answer would be more beneficial to explain the indexing error, why it happened, etc. so that OP actually learns something from it, not just copy-paste your code without even understanding what went wrong in the first place, which clearly they don't, hence the post. – ForeverZer0 Jul 15 '18 at 06:25