Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# change bool type in tuple when specific Error type is occurred

I have this Tuple

return new Tuple<bool, List<Error>, List<Error>>(false, errors, validErr);

I want to set bool to true if error type is TimeoutException

I tried to solve problem like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TimeoutException err = null

if(err is TimeoutException )

return new Tuple<bool, List<Error>, List<Error>>(true, errors, validErr);
}
else {
return new Tuple<bool, List<Error>, List<Error>>(false, errors, validErr);
}

I am not sure if this is correct or not. Any suggestions please?

>Solution :

use ternary operator to achieve it in less line of code.

 TimeoutException err = null
 bool hasTimeoutException = err is TimeoutException ? true : false;
 return new Tuple<bool, List<Error>, List<Error>>(hasTimeoutException, errors, validErr);

or you can directly add that ternary operator in return statement like below:

 return new Tuple<bool, List<Error>, List<Error>>(err is TimeoutException ? true : false, errors, validErr);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading