By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

cannot implicitly convert type string to bool

P: n/a
What's wrong with this?

if (bool)(UserIDs[i] == ThisUserId)
{
return true;
}

Mar 17 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
There's a closing "}", it's inside a function.

if (bool)(UserIDs[i] == ThisUserId)
{
return true;
}

Mar 17 '06 #2

P: n/a
private bool validateUserId(string ThisUserId, string[] UserIDs)
if (bool)(UserIDs[i] == ThisUserId)
{
return true;
}

Mar 17 '06 #3

P: n/a


You are not converting types here. the result of the == is a bool not
a string. It looks like missing parentheses

The statement should be something along the lines of

if ( (bool)(UserIDs[i] == ThisUserID) ) {
return true;
....

Although there should be no need for the (bool)

if ( UserIDs[i] == ThisUserID) {
return true;
...
hth,
Alan.

Mar 17 '06 #4

P: n/a
I'm guessing you mean if((bool) (UserIDs[i] == ThisUserId)) but the
explicit cast is redundant. What are the types of the variables listed?

Mar 17 '06 #5

P: n/a
there's no need for anything except return (UserIDs[i] == ThisUserID);

Mar 17 '06 #6

P: n/a

Sort of.

It's not clear from the original posting whether there was an altermate
action on if they didn't match ( there is no closing brace, so it
looks like a snippet rather than the whole routine.)

e.g

if ( UserIDs[i] == ThisUserID) {
return true;
}
else {
LogErrorMessage();
DoInterestingThings();
}
If the only thing that the routine does is check the validity of the
user ID and return true/false, then

return (UserIDs[i] == ThisUserID);

does suffice.
Alan.

Mar 18 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.