I am new to programming
I am coding in C# and its kind of confusing.
What is the difference between these:
Thank you very much in advance!
I am new to programming
I am coding in C# and its kind of confusing.
What is the difference between these:
Thank you very much in advance!
1- function uses to return an integer number
int main()
{
return 1;
}
so if you call this function like this:
int x = main();
result of x will be "1"
2- void function does n't return any value
void main()
{
Console.WriteLine("Hello World");
}
so you can call this function like this:
void main();
this just execute "void main" function and would not return anything
It looks like you are trying to answer a question on a programming quiz. If you are struggling with this basic of a question, I would question your rationale in attempting such a test.
Nevertheless, when starting out, it's useful to understand that:
int main(){...}
is a method that returns an integer.
void main(){...}
is a method that does not return a value.
The latter two lines in your image are not valid method declarations, because void
is placed as an input parameter, which is not a permitted usage of the void
keyword.
If you desire to understand what the void
keyword is really all about, you could start with What does void mean in C, C++, and C#? and Void (C# Reference) (Microsoft).