What is void actually?
In methods, it can be sort of used as a data type like int, double etc. but cannot be used in the declaration of a variable?
What is void actually?
In methods, it can be sort of used as a data type like int, double etc. but cannot be used in the declaration of a variable?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Jun 29, 2022, 1:53 AM EDT
Void keyword cannot assign any memory to the variable and hence it cannot be used for variable declaration.
so it is used as a return type only , just for methods.
For example WriteLine() is a method of Console class which just prints and doesn't return anything, so it's return type is Void.
Nitin SontakkeRank #264 · 9.6K reputationPosted Jul 1, 2022, 12:22 AM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Jun 28, 2022, 10:56 PM EDT
when your method do not return any values like int, string, complex object. That time you can use void return type. It means you do not have anything to return.
When you declare any variable means you are storing some value in it. That's the reason you can not use in variable declaration Vaibhav void.
Amit MohantyRank #112 · 20K reputationPosted Jun 29, 2022, 12:17 AM EDT
Jaydeep PatilRank #205 · 11.7K reputationPosted Jul 3, 2022, 2:28 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Jul 3, 2022, 12:33 PM EDT
In this context void means there is either nothing there or it is useless. It does not make sense to allocate a variable that does not exist or is useless.
In this context a method is the same as a function, such as C language functions. Languages have conventions for how values are returned from a function or method. When a function or method returns void, it means there is nothing in the defined location for a return value; anything that is there is useless.
Md SarfarajRank #194 · 12.4K reputationPosted Jul 5, 2022, 12:31 AM EDT