-4

I am new to programming
I am coding in C# and its kind of confusing.

What is the difference between these:
Method signatures

Thank you very much in advance!

Paul Smith
  • 3,104
  • 1
  • 32
  • 45
Mario
  • 1
  • 1
  • 3
  • I think you want to ask about difference of `main` method in C/C++. C# uses main method similar like Java has (without `void` argument): `static void Main()` or `static int Main()`. – Tetsuya Yamamoto Oct 05 '17 at 02:44
  • 4
    Possible duplicates of https://stackoverflow.com/questions/5296163/why-is-the-type-of-the-main-function-in-c-and-c-left-to-the-user-to-define & https://stackoverflow.com/questions/9356510/int-main-vs-void-main-in-c. – Tetsuya Yamamoto Oct 05 '17 at 02:48
  • Please add code, errors and data as **text** ([using code formatting](//stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](https://meta.stackoverflow.com/a/285557). In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, *in addition to text in code format*, if having the image adds something significant that is not conveyed by just the text code/error/data. – Makyen Oct 06 '17 at 04:20

2 Answers2

1

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

Saif
  • 2,611
  • 3
  • 17
  • 37
0

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).

Paul Smith
  • 3,104
  • 1
  • 32
  • 45