Call the methods private bool ReadAndValidateName(out string name) private bool ReadAndValidatePrice(out double price) this methods im i going to call in to private bool ReadAndValidateInput(out string name ,out double price) i know that im going to use
&& but i dont know how im going to call them?
Return true if both methods evaluate to a true value and
return false otherwise.
ok maybe im explad it wrong but. im going to call the 2 method in to private bool ReadAndValidateInput(out string name ,out double price) and then in it im going to Return true if both methods evaluate to a true value and
return false otherwise.
private bool ReadAndValidateInput(out string name, out double price)
{
Boolean b1 = ReadAndValidateName(out name);
Boolean b2 = ReadAndValidatePrice(out price);
return ReadAndValidateName(out name) && ReadAndValidatePrice(out price);
}
in this method you do not need to call both the methods individually, return code will do, but in this way --
Your methods will be called in the following order :
1. ReadAndValidateName will be called, and if it returns false, then ReadAndValidatePrice will not be called, because the final result is already clear, and does not depend on the result of the second method. 2. If ReadAndValidateResult returns true, then the final result will depend on the result of ReadAndValidatePrice, so, it will be called also. If it is important for you that the both two methods were called anyway, regardless of their results (you need to get name and price values for further use), then use & instead of &&.
Kalle_114
Member
15 Points
12 Posts
Call the methods
Feb 23, 2012 10:55 AM|LINK
Call the methods private bool ReadAndValidateName(out string name) private bool ReadAndValidatePrice(out double price) this methods im i going to call in to private bool ReadAndValidateInput(out string name ,out double price) i know that im going to use && but i dont know how im going to call them?
Return true if both methods evaluate to a true value and
return false otherwise.
karthicks
All-Star
31382 Points
5424 Posts
Re: Call the methods
Feb 23, 2012 11:07 AM|LINK
String name = "A"; Double price = 10; // you may assign value or leave it, in function you should assign value Response.Write(ReadAndValidateInput(out name, out price)); private bool ReadAndValidateInput(out string name, out double price) { Boolean b1 = ReadAndValidateName(out name); Boolean b2 = ReadAndValidatePrice(out price); return ReadAndValidateName(out name) && ReadAndValidatePrice(out price); } private bool ReadAndValidateName(out string name) { name = "abc"; if (name.Length > 0) return true; return false; } private bool ReadAndValidatePrice(out double price) { price = 10; if (price > -1) return true; return false; }Karthick S
Kalle_114
Member
15 Points
12 Posts
Re: Call the methods
Feb 23, 2012 11:33 AM|LINK
ok maybe im explad it wrong but. im going to call the 2 method in to private bool ReadAndValidateInput(out string name ,out double price) and then in it im going to Return true if both methods evaluate to a true value and
return false otherwise.
private bool ReadAndValidateName(out string name) { } private bool ReadAndValidatePrice(out double price) { } private bool ReadAndValidateInput(out string name ,out double price) { }sudhir.kathu...
Member
212 Points
43 Posts
Re: Call the methods
Feb 23, 2012 11:51 AM|LINK
private bool ReadAndValidateInput(out string name, out double price) { Boolean b1 = ReadAndValidateName(out name); Boolean b2 = ReadAndValidatePrice(out price); return ReadAndValidateName(out name) && ReadAndValidatePrice(out price); } in this method you do not need to call both the methods individually, return code will do, but in this way --private bool ReadAndValidateInput(out string name, out double price) { return ReadAndValidateName(out name) & ReadAndValidatePrice(out price); }Sud
AlexERS
Member
14 Points
2 Posts
Re: Call the methods
Feb 29, 2012 09:40 AM|LINK
Your methods will be called in the following order :
1. ReadAndValidateName will be called, and if it returns false, then ReadAndValidatePrice will not be called, because the final result is already clear, and does not depend on the result of the second method.
2. If ReadAndValidateResult returns true, then the final result will depend on the result of ReadAndValidatePrice, so, it will be called also.
If it is important for you that the both two methods were called anyway, regardless of their results (you need to get name and price values for further use), then use & instead of &&.