C
C#2y ago
Soinagie

❔ what is string[] args?

As title says
92 Replies
Denis
Denis2y ago
Input arguments passed into the application Said arguments are passed when, e g. running a console application from the command line
Soinagie
SoinagieOP2y ago
Then why is is string [] args and not just method (some value)
Denis
Denis2y ago
Not sure what you are asking. string[] is an array of strings. Meaning you have multiple strings Each representing an argument
Soinagie
SoinagieOP2y ago
Also what application? Do you mean program?
Denis
Denis2y ago
Yes
SG97
SG972y ago
Main() and command-line arguments
Learn about Main() and command-line arguments. The 'Main' method is the entry point of an executable program.
Denis
Denis2y ago
Either a console based application or a GUI application such as WinForms or WPF
Soinagie
SoinagieOP2y ago
Okay but i could've done it without args Just string [] If its an argument
SG97
SG972y ago
?
Denis
Denis2y ago
args is the name of the input parameter You cannot ommit it
SG97
SG972y ago
you can leave the parameters out completely if not needed
Soinagie
SoinagieOP2y ago
Ommit what Im way too confused now I have a method and put some value in it so its method (value)
SG97
SG972y ago
I thought you meant the Main method
Soinagie
SoinagieOP2y ago
Main is also a method
Denis
Denis2y ago
When you use a method, you do indeed put a value into it
SG97
SG972y ago
can you post some $code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Denis
Denis2y ago
When you define a method, that can be used, you have to write it's parameters. Each parameter must have a data type and a name Of course, you can have a method without parameters E.g.:
Soinagie
SoinagieOP2y ago
cs
class Car
{
string color = "red";

static void Main(string[] args)
{
Car myObj = new Car();
Console.WriteLine(myObj.color);
}
}
cs
class Car
{
string color = "red";

static void Main(string[] args)
{
Car myObj = new Car();
Console.WriteLine(myObj.color);
}
}
Its from w3school
SG97
SG972y ago
what's the issue
Soinagie
SoinagieOP2y ago
I don't know what string[] args is
SG97
SG972y ago
a parameter
Soinagie
SoinagieOP2y ago
What parameter
Denis
Denis2y ago
A parameter for receiving command line arguments
Soinagie
SoinagieOP2y ago
Yeah I dont know what command line is
Denis
Denis2y ago
Ok I'll try and explain Have you run a Console application yet? A black window appears with, e.g., some text
Soinagie
SoinagieOP2y ago
Yeah
Denis
Denis2y ago
That black window is called Command prompt in Windows. You can open it by searching command prompt Or CMD for short
Soinagie
SoinagieOP2y ago
So its just input to console? Command line I mean
Denis
Denis2y ago
Soinagie
SoinagieOP2y ago
I don't have my pc with me
Denis
Denis2y ago
And in it, you enter commands. You can call a command and specify arguments to it If you'd call a c# console program a give an argument to it, you'd receive it via the args parameter
Soinagie
SoinagieOP2y ago
Couldn't you just do console.WriteLine () Method (console.ReadLine ())?
Denis
Denis2y ago
No this is something different
Soinagie
SoinagieOP2y ago
Whats args?
Denis
Denis2y ago
Here the main method is being defined, not called
Soinagie
SoinagieOP2y ago
Yeah I know
Denis
Denis2y ago
You don't call the main method, as it is a special method. It is called when an application is started And sometimes you don't want to do readline
Soinagie
SoinagieOP2y ago
Is main method different than other methods?
Denis
Denis2y ago
You want to specify arguments straight away
Soinagie
SoinagieOP2y ago
I mean you can use both same way But this method I posted isn't in Main
Denis
Denis2y ago
But I can see main
Soinagie
SoinagieOP2y ago
Wait you're right Im confused how is it in a class
Denis
Denis2y ago
Main is always in a class But it is true that it shouldn't be in Car Doesn't really make sense there It is usually in the Program class
Soinagie
SoinagieOP2y ago
Ok back to my question what is string[] args
Denis
Denis2y ago
-v is an argument
Denis
Denis2y ago
You get v into your program via the string[] args method parameter node is some program
Soinagie
SoinagieOP2y ago
Im confused about all these parameters and arguments I mean I read what they are And I still don't get it You just wrote program and added "-v" to it
Denis
Denis2y ago
It's not really something you should worry about now, to be honest. However, it'd be best if you tried it out. Figure out how to run a Console application from the command prompt Yes -v is some argument
Soinagie
SoinagieOP2y ago
Its a string
Denis
Denis2y ago
An extra value Yes
Soinagie
SoinagieOP2y ago
Not an argument
Denis
Denis2y ago
String is a data type Argument is a value of some data type, that a program receives as input
Soinagie
SoinagieOP2y ago
So arguments are just inputs?
Denis
Denis2y ago
Yes
Soinagie
SoinagieOP2y ago
THEN CALL THEM INPUTS😭 So string[] args is adding a value to a method? In a string Or series of them as it uses []
Denis
Denis2y ago
string [] args means that a method receives a set of strings, that represent input arguments String[] is an array of strings
Soinagie
SoinagieOP2y ago
And I seperate them with "," right? Does it just add text to a method or somehow change it how it may work?
Denis
Denis2y ago
Usually with spaces. I'm not too well versed with command line argument processing Based on what your main method gets via the string[] args you usually change how your program behaves
Soinagie
SoinagieOP2y ago
Its just a text It won't change a number
Denis
Denis2y ago
You'd write, e.g., if conditions check is the args contains a specific string. And if it does, you do something
SG97
SG972y ago
a parameter itself does nothing
Soinagie
SoinagieOP2y ago
Ok and args is ALWAYS an input
SG97
SG972y ago
what
Soinagie
SoinagieOP2y ago
. .
SG97
SG972y ago
sure
Soinagie
SoinagieOP2y ago
And args are a type of parameter
SG97
SG972y ago
a string array to be exact
Soinagie
SoinagieOP2y ago
That you use in method Right?
SG97
SG972y ago
if you introduce a parameter in the method signature, you usually do something with it otherwise don't
Soinagie
SoinagieOP2y ago
Whats signature?
Denis
Denis2y ago
The way a method is defined
Soinagie
SoinagieOP2y ago
Like static?
SG97
SG972y ago
Methods - C# Programming Guide
A method in C# is a code block that contains a series of statements. A program runs the statements by calling the method and specifying arguments.
Denis
Denis2y ago
private void MyMethod(int input) This is a signature
SG97
SG972y ago
no
Denis
Denis2y ago
My suggestion is to ignore the specifics such as the string[] args, and focus on c# fundamentals
SG97
SG972y ago
start practising with $helloworld
Soinagie
SoinagieOP2y ago
I just thought I should know what different things do if I want to know how code works
Denis
Denis2y ago
I feel that you are missing a lot of crucial knowledge to fully understand our explanations... That is true However, you can't understand everything at once... Unfortunately
Soinagie
SoinagieOP2y ago
Ok so for now parameter is additional information for a method Argument is an inputted parameter Sigantures are things like public and void
SG97
SG972y ago
well
Denis
Denis2y ago
Well, not exactly when
Soinagie
SoinagieOP2y ago
Im just a begginer😭
Denis
Denis2y ago
The signatures part isn't quite right
SG97
SG972y ago
nor is the argument it's not "inputted" as in a user types something
Denis
Denis2y ago
We know, no stress. We had to give you a lot of new information here and it is quite overwhelming
SG97
SG972y ago
but to me, this is kinda going nowhere. Better to start doing and learn as you go
Soinagie
SoinagieOP2y ago
Ok I appriciate your help thank you very much<:millia_love:856302466030370846>
Denis
Denis2y ago
Keep learning, don't give up. You've got a long and exciting road ahead of you. And don't hesitate to ask more questions, even if you might get a headache from the answers....
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server