+ 2
C# Void
If void is a valueless state, then why can I still write and read lines inside static void main?
4 odpowiedzi
+ 2
It just means that you cannot return anything from the main method but you can do anything apart from that.
+ 2
Caleb Kious if you move ahead in the course then you will learn about methods and return types. 'Writeline' itself is a method and Console is a class.
Void means it doesn't return a value. It can be replaced by primitive data types such as string, int, double etc depending upon what you want to return from your method.
+ 1
So WriteLine doesn’t return a value in the main method?
static void main(string[] args) {
Console.WriteLine(“Where is this data?”); }
+ 1
No. Only return returns a value. WriteLine is an Output for User Information or something. If you have a value and you want use it outside a Method. Then use return. Example:
int sum = Calculate(5,7); // 12 is in sum
int Calculatr(int a, int b)
{
Console.WriteLine(quot;{a}+{b} is {a+b}");// That is just a user Info
return a+b; //This is the value which will be return
}