indexing - Error : Index was outside the bounds of the array in c# -
this question has answer here:
i'm trying write small program using c# interface concept area of circle & square.while giving specific condition if (args[0] == "s")
there error indexoutofrangeexception
:
if (args[0]=="s") fig = new square(); if (args[0]=="c") fig = new circle();
that happen if args
empty. can't ask first element of empty array, because there isn't one. should check length first:
if (args.length == 0) { // maybe exit? valid not specify arguments? } // either use "else" here, or if you've quit in "if" block // don't need because know there's @ least // 1 argument
Comments
Post a Comment