Can there be a function which doesn't return values ?
Is it mandatory to have return value for every function in c# ?
7 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Sujeet SumanRank #790 · 2.9K reputationPosted Dec 17, 2015, 9:12 PM EST
✓ Accepted answer+1
Yes Bhanuchandra if you are using return type void, then that function doesn't return value.
And it is not mandatory to return a value for every function in c#.
So if you want to return a value then use the same return type in method declaration what type you want to return. And if you don't want to return any value then use return type void in method declaration.
Example:
// Method with no return type
int sum = 0;
public void ADD(int a, int b)
{
sum = a + b;
}
// Method with return type integer
public int ADD(int a, int b)
{
return (a + b);
}
If this is helpful for you then please accept my Answer.
Tapan DubeyRank #8,900 · 214 reputationPosted Dec 17, 2015, 6:06 AM EST
+1
Dear Bhanuchandra ,
if return type of function is void so it doesn't return any value. for example -
public void SaveRecord()
{
// This doesn't return anything...
}
+1
Rajeesh MenothRank #118 · 18.4K reputationPosted Dec 17, 2015, 6:31 AM EST
0
Hi,
Void doesn't have any return type.When you are using string,int,bool,etc then you must provide the return type.based on ur requirement you can use both one.
0
Rajesh SinghRank #1,806 · 824 reputationPosted Dec 17, 2015, 9:17 PM EST
0
Hi
It is not mandatory to have return type in C#.
When you use void return type then no need to return, but if you are using any other return type like int, string, double etc, then it should return values based on return type.
Sujeet SumanRank #790 · 2.9K reputationPosted Dec 17, 2015, 9:12 PM EST
Tapan DubeyRank #8,900 · 214 reputationPosted Dec 17, 2015, 6:06 AM EST
Rajeesh MenothRank #118 · 18.4K reputationPosted Dec 17, 2015, 6:31 AM EST
Rajesh SinghRank #1,806 · 824 reputationPosted Dec 17, 2015, 9:17 PM EST
Francis SusaimichaelRank #466 · 5.4K reputationPosted Dec 18, 2015, 1:29 AM EST
MahaRank #2,573 · 543 reputationPosted Dec 18, 2015, 2:02 AM EST
There are many functions which doesn’t have return value.
No there is no mandatory to have return value.
I have developed same program with return and without return for curiosity.
Dharmesh SinghRank #1,207 · 1.5K reputationPosted Dec 17, 2015, 6:25 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts