Re: returning a string and bool type from a member of a class

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Paul wrote:
Hi I have the method below that returns a bool, true or false depending
on if the conversion to date tiem works. It takes a string input. I am only returning the bool but would also like to return the string message ex.message, just wondering how to do this since I think you can only return one thing with the function. Thanks.

public bool checkdate(String s_date)
{
b_convert = true ;
DateTime dt_temp1 = Convert.ToDateTime("1/1/1980");
try
{
dt_temp1 = Convert.ToDateTime(s_date);
}
catch (Exception ex)
{
errormsg = ex.Message;
b_convert = false;
}
return b_convert;
}

An alternative to the out parameter recommended by several you
could return a struct.

Arne
.



Relevant Pages

  • Re: returning a string and bool type from a member of a class
    ... on if the conversion to date tiem works. ... It takes a string input. ... only returning the bool but would also like to return the string message ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: returning a string and bool type from a member of a class
    ... on if the conversion to date tiem works. ... It takes a string input. ... only returning the bool but would also like to return the string message ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: I Need an IsNumeric Method
    ... public bool IsNumeric ... //Try a double conversion. ... try to convert and catch the exception ... > o Don't forget that .5 is generally considered okay, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Testing for nullptr for a ref object
    ... I'm must admit I haven't read much of the C++/CLI standard. ... my interpretation is that the compiler will consider a conversion ... from x to bool better than the check against nullptr. ... So if a conversion from x to bool exists it will be chosen over the ...
    (microsoft.public.dotnet.languages.vc)
  • Re: void * instead of bool
    ... Earth would I definitily not want that to compile? ... One is that perhaps the original design dates from a time before 'bool' ... ifstream object to a constructor where one overload takes a bool. ... the latter case the conversion to ...
    (comp.lang.cpp)