‫Whenever you create a console application in Visual Studio, you end up with your main method.
‫And this main method has this string arcs.
‫So this array of strings that is called arcs.
‫But what is this?
‫What is this arcs?
‫And how can we use it?
‫Well, that's what we're going to cover in this video.
‫This is actually a very important aspect of any console application, but usually you don't use it in
‫tutorials.
‫So that's what we're going to change this time.
‫The main method arguments.
‫Called Arcs here, which is an array of strings, is an object that gets passed to the main method once
‫the application has started.
‫So the main idea behind it is to provide our application with all the necessary input it needs to do
‫its job without pausing it to take input from the user using, for example, the console red line.
‫So it could also be used to give our application input that is coming from a different application which
‫we will see in a later video.
‫So for now, let's start with this simple example.
‫Therefore, I'm going to go over to my properties here.
‫So right click properties on your application and then after a while this window should pop up.
‫And here if you go to debug, you will find your application arguments.
‫So this could be called, for example, command line arguments in your case, depending on which version
‫of Visual Studio you're using and also of which version you're using for your console application.
‫But it's either application arguments or command line arguments.
‫So here you can now enter something like, for example, tennis, that's my name.
‫So I'm going to put that in here.
‫You can put your own name in there, and then in your main method you can just say something like Hello
‫and then the name.
‫So here ARX at the position zero because this argument Denis will now be given to my ARX so to my main
‫method so to speak, and will be stored inside of ARX.
‫And ARX is an array so we can access its positions using the index here and at index zero.
‫Now we will find Denis.
‫So let's run this application real quick and we will realize that it says Hello Denis.
‫Now if we were to add another statement here with an empty space separating the two words, this is
‫basically a new entry inside of the array.
‫So if you want to now access Frank, we would change this from ARX at position zero to ARX in position
‫one.
‫So you need to understand what the rules are, of course, in order to achieve any of this and understand
‫it.
‫So you see here now it says Hello, Frank.
‫So that seems to work.
‫But what if this is empty so we don't pass any arcs and we try to run it?
‫Well, then we are running into an error here.
‫It says index out of range exception.
‫So let's fix that real quick.
‫Let's fix this because we never know how many arguments will be given to our application if we run it.
‫So let's go ahead and double check it first.
‫So what we're going to do is we're going to check for the length of the array.
‫So let's go ahead and use our X length equal equals zero.
‫So here we are comparing the length of the arguments to zero.
‫And if it is zero, then we're just going to say this is a smart app that uses ARX.
‫Please provide arguments next time and then the user can press enter or whatever key he wants to then
‫finally return, which basically will close our application.
‫So it will return out of the main method, which basically will close the application.
‫And if that's not the case, so if it doesn't return, which means it doesn't close the application,
‫shut it down, then it will get to this line.
‫But in order to actually see this line, I need to also add a read key here because otherwise the application
‫will not display it correctly.
‫So I'm going to change that back to arcs at position zero because I'll just enter one value.
‫And now I would like to actually run this application first to check if it's going to say this is a
‫smart app and it does so now because the arc length is zero, because here we didn't add any arguments.
‫This will not display anything useful to us.
‫So it will of course say that the application needs an argument to do anything.
‫So now let's actually run this application from the command line prompt because that's the idea of console
‫applications that you can run them from the command line prompt.
‫So how do I get to my application?
‫So to the Excel file, well, I can open up the solution explorer.
‫Right click here and go to open folder and file path or file explorer.
‫This will give you the path there you go to the bin folder and then the debug folder and my case it's
‫dot net five, but maybe in your case the Excel file will directly appear there or you just have to
‫go one folder down depending on which version you're using.
‫So here we have our main arts demo exa, which is basically our application which says this is a smart
‫app that uses args.
‫Please provide arguments next time.
‫So how can I actually pass arguments to this exa?
‫Because well, it's an excellent I executed it and I couldn't enter anything.
‫So what's up here?
‫Well, let's actually fix that by opening the command prompt.
‫So press the windows key and then enter CMD or press the windows key at the bottom of your screen and
‫then search for CMD and press enter to open your command prompt.
‫So this will pop up.
‫In my case it's the German version which says Angel Bar Photon.
‫So here I can now drag in my main args demo like so and I can run the application so you can see it
‫says this is a smart app that uses ARX.
‫Please provide arguments next time.
‫Okay, so let's do that.
‫Let's actually provide arguments next time.
‫So I'm going to press the up arrow twice here and then I'm going to leave an empty space to then enter
‫the name.
‫So here, for example, Denis, and it says Hello Denis.
‫So you can see our application now received this Denis as an argument.
‫And then because the arguments weren't empty, so the length wasn't zero, it went over to this line
‫and executed it and just said hello and then whatever argument was given to it.
‫This is something very simple.
‫And in this particular example, it's super simple, but it's really powerful because there are many
‫things that you can do with it now.
‫You can really build your console applications a lot more complexly, and you could even double check
‫what was entered, what kind of arguments were given, how many arguments were given and so forth.
‫And based your applications execution on whatever was given to your application when it was started
‫using the command prompt.
‫So console apps are super important and they play a huge role in the apps that we use daily.
‫And so far we really didn't use them in general throughout my courses.
‫But now it was really time to actually show you how to do it.
‫So actually a lot of tools come in the shape of console applications which we can either use directly
‫or make our code use them by sending and receiving input and output from them.
‫In the next video, we're going to check out how we can handle user input and that our application do
‫basic operations.