+ 2

C# Void

If void is a valueless state, then why can I still write and read lines inside static void main?

4th Apr 2020, 6:26 PM
Caleb Kious
Caleb Kious - avatar
4 Respostas
+ 2
It just means that you cannot return anything from the main method but you can do anything apart from that.
4th Apr 2020, 6:46 PM
Avinesh
Avinesh - avatar
+ 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.
5th Apr 2020, 3:51 AM
Avinesh
Avinesh - avatar
+ 1
So WriteLine doesn’t return a value in the main method? static void main(string[] args) { Console.WriteLine(“Where is this data?”); }
4th Apr 2020, 8:58 PM
Caleb Kious
Caleb Kious - avatar
+ 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 }
5th Apr 2020, 12:52 AM
Nils Diercks
Nils Diercks - avatar