I want to check multiple conditions in a string in C# but it throws error saying Cannot use && for string or boolean
if ((duStart.Trim() != "" && duStart.Trim() != null) &&(duEnd.Trim() != "" && duEnd.Trim() != null))
{
//do this
}
else
//do that
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The code you’ve given compiles fine. Here’s a short but complete program – I’ve changed the whitespace of your line of code, but that’s all:
Having said that:
duStart, for example) multiple times, there seems little point in computing it twice. I’d have used extra local variables (trimmedStart,trimmedEnd) hereTrimnever returns null, so those tests are pointless.string.IsNullOrWhitespaceis probably a better idea here. Why bother creating strings that you’re never going to use?