+ 1
Purpose of void?
If void returns nothing, than why do we need it? In which cases we use “void” instead of “int”?
3 Respostas
+ 3
Void means if this method gets used nothing is returned to were that method was called most of the time these methods will print somthing that's just because that peice of code is inside the method and gets executed.
A return type of int means if this method gets called do some work with the arguments you passed in and return the result back to were that method was called but you promise that the result returned will be an int value.
+ 1
Sometimes you just want a method to do something for you.
Like this method (sorry I wrote it in c#)
Why should it return a value ?
public void PrintName(string Name)
{
Console.WriteLine(Name);
}