C# Void | SoloLearn: Learn to code for FREE!


C# Void

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


4/4/2020 6:26:06 PM

Caleb Kious

4 Answers

New Answer


It just means that you cannot return anything from the main method but you can do anything apart from that.


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.


So WriteLine doesn’t return a value in the main method? static void main(string[] args) { Console.WriteLine(“Where is this data?”); }


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($"{a}+{b} is {a+b}");// That is just a user Info return a+b; //This is the value which will be return }