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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -