Click here to Skip to main content
15,902,198 members
Home / Discussions / C#
   

C#

 
AnswerRe: return type error "not all code paths return a value" Pin
Som Shekhar10-May-10 5:35
Som Shekhar10-May-10 5:35 
GeneralRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 6:15
wjbjnr10-May-10 6:15 
GeneralRe: return type error "not all code paths return a value" Pin
Som Shekhar10-May-10 6:48
Som Shekhar10-May-10 6:48 
QuestionRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 7:59
wjbjnr10-May-10 7:59 
AnswerRe: return type error "not all code paths return a value" Pin
Som Shekhar10-May-10 8:03
Som Shekhar10-May-10 8:03 
GeneralRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 8:43
wjbjnr10-May-10 8:43 
GeneralRe: return type error "not all code paths return a value" Pin
Som Shekhar10-May-10 8:59
Som Shekhar10-May-10 8:59 
GeneralRe: return type error "not all code paths return a value" Pin
OriginalGriff10-May-10 9:03
mveOriginalGriff10-May-10 9:03 
They are not the same.
They just look it because you don't see what is happening.
Indenting your code shows why they are different:
public bool e(int x)
   {
   if (x <= 2 && x>=0)
      return true;
   for (int i = 2; i<;x; i++)
      if (x % i == 0)
         return false;
   return true;
   }

and
public bool e(int i)
   {
   if (i <= 2 && i >= 0)
      return true;
   for (int f = 2; f <= i; f++)
      {
      if (i % f == 0)
         {
         return false;
         }
      else
         {
         return true;
         }
      }
   }

In the first case, there is always a return statement - in every exit path.
In the second case, the compiler assumes there is an exit path at the end of the loop that does not have a return statement. It doesn't need one, because your loop is crap - it will always return on the first iteration. But the compiler doesn't know that. It does not look at "i % 1" and say: that will always be 0 or 1, so there is a control path that ends in a return for all cases. It just looks and sees a control path after the loop that will never include a return.
Surprisingly, the compiler is not as intelligent as you.
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.

Apathy Error: Don't bother striking any key.

GeneralRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 9:51
wjbjnr10-May-10 9:51 
QuestionListBox.DisplayName problem Pin
reza assar10-May-10 0:29
reza assar10-May-10 0:29 
AnswerRe: ListBox.DisplayName problem Pin
Heinzzy10-May-10 0:47
Heinzzy10-May-10 0:47 
GeneralRe: ListBox.DisplayName problem Pin
reza assar11-May-10 1:56
reza assar11-May-10 1:56 
Questioncreating a setup in c#.net Pin
prasadbuddhika9-May-10 23:36
prasadbuddhika9-May-10 23:36 
AnswerRe: creating a setup in c#.net Pin
Pete O'Hanlon10-May-10 0:15
mvePete O'Hanlon10-May-10 0:15 
AnswerRe: creating a setup in c#.net Pin
Abhinav S10-May-10 0:34
Abhinav S10-May-10 0:34 
AnswerRe: creating a setup in c#.net Pin
prasadbuddhika10-May-10 6:30
prasadbuddhika10-May-10 6:30 
QuestionSNMP From C# Pin
Anders Molin9-May-10 23:26
professionalAnders Molin9-May-10 23:26 
Questionretrieving PDF from SQL database and printing it in C# Pin
mrkeivan9-May-10 22:50
mrkeivan9-May-10 22:50 
AnswerREPOST from only a few hours ago Pin
Pete O'Hanlon9-May-10 23:52
mvePete O'Hanlon9-May-10 23:52 
QuestionReg: Disabling single item of CheckedListBox in C# - Pin
hemamerp9-May-10 22:28
hemamerp9-May-10 22:28 
AnswerRe: Reg: Disabling single item of CheckedListBox in C# - Pin
Heinzzy9-May-10 23:19
Heinzzy9-May-10 23:19 
Questionread data from modem Pin
A_Fa9-May-10 21:54
A_Fa9-May-10 21:54 
AnswerRe: read data from modem - Repost Pin
Richard MacCutchan9-May-10 22:03
mveRichard MacCutchan9-May-10 22:03 
QuestionOLEDB PROBLEM Pin
elizabeth mwash9-May-10 21:51
elizabeth mwash9-May-10 21:51 
AnswerRe: OLEDB PROBLEM Pin
Estys9-May-10 22:07
Estys9-May-10 22:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.