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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Md SarfarajPosted Jul 5, 2022, 4:31 AM
Sam HobbsPosted Jul 3, 2022, 4:33 PM
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.
Jaydeep PatilPosted Jul 3, 2022, 6:28 AM
Nitin SontakkePosted Jul 1, 2022, 4:22 AM
Sachin SinghPosted Jun 29, 2022, 5:53 AM
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.
Amit MohantyPosted Jun 29, 2022, 4:17 AM
Jignesh KumarPosted Jun 29, 2022, 2:56 AM
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.