Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan16-May-13 5:02
mveRichard MacCutchan16-May-13 5:02 
GeneralRe: Method Not Returning a Value Pin
N8tiv16-May-13 6:13
N8tiv16-May-13 6:13 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan16-May-13 6:46
mveRichard MacCutchan16-May-13 6:46 
GeneralRe: Method Not Returning a Value Pin
N8tiv16-May-13 7:42
N8tiv16-May-13 7:42 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan16-May-13 20:40
mveRichard MacCutchan16-May-13 20:40 
GeneralRe: Method Not Returning a Value Pin
N8tiv17-May-13 11:31
N8tiv17-May-13 11:31 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan17-May-13 22:50
mveRichard MacCutchan17-May-13 22:50 
GeneralRe: Method Not Returning a Value Pin
Pete O'Hanlon14-May-13 23:07
mvePete O'Hanlon14-May-13 23:07 
Rob, I see several problems in your code here. Let's break down some of the more apparent errors (I'm ignoring style issues such as using Pascal casing for variables):
C#
string valueOne = Console.ReadLine();
int IntOne = 0;
bool result = Int32.TryParse(valueOne, out IntOne);
if (!result)
{
  Console.WriteLine("Attempted conversion of '{0}' failed.", IntOne);
  AcceptValueOne();
}
In this section of code, you call AcceptValueOne again, and you aren't returning anything from it. The issue you have here is that you are recursively calling this method is completely unecessary, and also will return 0 to the calling function if the condition fails the first time (also, you are using the failed conversion in your WriteLine). This could easily be solved with a loop instead:
C#
bool result = false;
do
{
  string valueOne = Console.ReadLine();
  result = Int32.TryParse(valueOne, out IntOne);
  if (!result)
  {
    Console.WriteLine("Attempted conversion of '{0}' failed, please try again.", valueOne);
  }
} while (!result);
As you can see, the test is straightforward and there's no recursion. Well, as you can see, the same logic applies in cases where you are doing your tests for the y/n combination.

Another problem with your code is that you have two paths to AcceptValueTwo - the one in AcceptValueOne is completely useless because you aren't doing anything with the value. You're actually getting this value elsewhere (by the way, your code won't compile at the moment because you have a class level variable that's calling a method - and this is something you can't do; also, your valOne and valTwo members aren't static which means they won't be visible in any of your static methods).
I was brought up to respect my elders. I don't respect many people nowadays.

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Method Not Returning a Value Pin
N8tiv15-May-13 20:37
N8tiv15-May-13 20:37 
GeneralRe: Method Not Returning a Value Pin
Pete O'Hanlon15-May-13 23:50
mvePete O'Hanlon15-May-13 23:50 
GeneralRe: Method Not Returning a Value Pin
N8tiv16-May-13 0:29
N8tiv16-May-13 0:29 
GeneralRe: Method Not Returning a Value Pin
Pete O'Hanlon16-May-13 0:36
mvePete O'Hanlon16-May-13 0:36 
QuestionCreating Images on Different Layers Pin
ASPnoob14-May-13 11:40
ASPnoob14-May-13 11:40 
AnswerRe: Creating Images on Different Layers Pin
Ravi Bhavnani14-May-13 11:48
professionalRavi Bhavnani14-May-13 11:48 
AnswerRe: Creating Images on Different Layers Pin
SledgeHammer0114-May-13 12:51
SledgeHammer0114-May-13 12:51 
QuestionC# how save form in pdf/ and about calendar Pin
ghost22th14-May-13 4:39
ghost22th14-May-13 4:39 
AnswerRe: C# how save form in pdf/ and about calendar Pin
Richard MacCutchan14-May-13 5:11
mveRichard MacCutchan14-May-13 5:11 
QuestionSENDING MAIL DID NOT USING GMAIL DOMAIN Pin
mohamed kalif raja14-May-13 0:54
mohamed kalif raja14-May-13 0:54 
AnswerRe: SENDING MAIL DID NOT USING GMAIL DOMAIN Pin
Pete O'Hanlon14-May-13 2:10
mvePete O'Hanlon14-May-13 2:10 
GeneralRe: SENDING MAIL DID NOT USING GMAIL DOMAIN Pin
N8tiv14-May-13 19:40
N8tiv14-May-13 19:40 
GeneralRe: SENDING MAIL DID NOT USING GMAIL DOMAIN Pin
Pete O'Hanlon14-May-13 20:52
mvePete O'Hanlon14-May-13 20:52 
GeneralRe: SENDING MAIL DID NOT USING GMAIL DOMAIN Pin
N8tiv14-May-13 20:53
N8tiv14-May-13 20:53 
AnswerRe: SENDING MAIL DID NOT USING GMAIL DOMAIN Pin
N8tiv14-May-13 20:55
N8tiv14-May-13 20:55 
GeneralRe: SENDING MAIL DID NOT USING GMAIL DOMAIN Pin
mohamed kalif raja17-Jun-13 22:12
mohamed kalif raja17-Jun-13 22:12 
QuestionMessage Closed Pin
14-May-13 0:36
JAYRAJ GIRI14-May-13 0:36 

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.