0

I am a complete beginner in C# and this is kind of my first project. So what I am trying to do is, make a console app and directly put input in the app for displaying but I am facing some difficulties in doing so.

Problem 1: Getting an error message

Problem 2: Cant find the debugging options under configuration properties

Please find the attached images of the errors.

Sayan Kar
  • 9
  • 3
  • Please create separate Stack Overflow questions for each question you have. – STLDev Sep 25 '18 at 20:18
  • Check this question and do the necessary input validation as it is shown in the answer https://stackoverflow.com/questions/3697299/passing-command-line-arguments-in-visual-studio-2010 – Mahmoud Fayez Sep 25 '18 at 20:18
  • 2
    Your code is short and the error message is simple, so it would be great if you could include them in your question rather than linking them as images. It makes it much easier for answerers to do their stuff. – Rook Sep 25 '18 at 20:19
  • 2
    Anyway, that said: problem 1 is simple, because the error message tells you everything you need to know: the args array is empty, so even index 0 is out of range. – Rook Sep 25 '18 at 20:20
  • 1
    Welcome! Please do not post screenshots of your code and/or error messages (something to read: [Why not upload images of code on SO when asking a question?](https://meta.stackoverflow.com/a/285557/2819245), [An image of your code is not helpful](http://idownvotedbecau.se/imageofcode) and [Pictures of exceptions are not helpful](http://idownvotedbecau.se/imageofanexception/)). –  Sep 25 '18 at 20:25
  • Also, you are never too fresh, never too green and never too much of a beginner to not dip your toes into the debugger of Visual Studio ([Learn to debug using Visual Studio](https://learn.microsoft.com/en-us/visualstudio/debugger/getting-started-with-the-debugger)) ;-) –  Sep 25 '18 at 20:27

2 Answers2

1

Problem 1: The error message is occurring because you aren't passing any arguments to your application, so the array has no elements. Accessing index 0 of an empty array will throw the exception you see.

Problem 2: Looks like you're selecting the solution's properties instead of your project's properties. Instead:

  • Right click on the application (not the solution) in your solution explorer. In your case this is the bolded ConsoleApp2
  • Select 'properties'
  • In the tab that opens, select 'Debug'
  • Enter something into the "Application Arguments" box
Hofma Dresu
  • 432
  • 3
  • 13
1

To Problem 1

You do not pass any args thus args[0] leads to the non-existing first element which then correctly throws the exception

To Problem 2

You selected the solution. To change properties of a project (which you probably want to do to add some argument to your debuging session so Problem 1 goes away), you need to select the actual project, not the solution.

X39
  • 789
  • 6
  • 22