Not all code paths return a value

Not all code paths return a value


 As error it self says, the code is not returing any value. Lets reproduce that error.
Here I will create a function that will return sum of two numbers. 

 public int  Sum( int a , int b )
 {
    
    int x  = a + b;  
  
 } 

if you compile above code  you will get an error "Not all code paths return a value", because
your function Sum is supposed to return value but function is not returning any value. Lets fix it by putting keyword
return.


public int  Sum( int a , int b )
 {
    
    int x  = a + b;  

    return x;
  
 }

If you don;t want to return anything use void

public void Sum( int a , int b )
 {
    
    int x  = a + b;  
  
 }

I hope you understood, why you are getting "No all code paths return value" error.

Satalaj

Tags:

Jquery Dropdown Selected ValuePaypal purpose code IndiaAsp.net access html control textbox element value at code behindError The SSIS Runtime has failed to start the distributed transaction due to error 0x8004D01B The Transaction Manager is not available The DTC transaction failed to start This could occur because the MSDTC Service is not runningJQuery Hidden Field Set ValueDo Not Disturb Registry [dnd]How to get Jquery selected optionGet Selected Value From Dropdownlist [JQuery]JQuery TextBox Value()Asp.net Urldecode QueryStringUrl Encode In Asp.net

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.