Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the best practice for returning a Boolean and string value

Tags:

c#

I've created a method that performs some validations against an XML Hierarchy that is dynamically generated by another Class in Javascript text during run time.

My method currently returns either True or False, which is helpful for anyone using my Class but I'd like to also return more informative information since there may be several reasons that can throw a False message.

At first I thought to change the return type from bool to some Generic Collection type having a String key and Boolean value I don't know if this is the best approach.

What is the Best Practice in this case?

like image 491
Mark Avatar asked May 11 '11 11:05

Mark


People also ask

How do you return a boolean and a string in Java?

toString(boolean b) returns a String object representing the specified boolean. If the specified boolean is true, then the string "true" will be returned, otherwise the string "false" will be returned.

What should I return in boolean?

Boolean functions must return something boolean. Non-boolean functions must not return something boolean. Comparisons, logical AND/OR, and true/false macros are bool.

Does boolean return a value?

Return Value:It returns true, if the Boolean objects represent the same value. It returns false, if the Boolean objects represent different value.


1 Answers

Make a class like

public class ValidationResponse
{
    public bool Successful { get; set; }
    public string Information { get; set; }
}

and return object of ValidationResponse

like image 51
dhinesh Avatar answered Oct 05 '22 14:10

dhinesh