Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2006

Tip: Looking for answers? Try searching our database.

cannot implicitly convert type string to bool

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
eric.goforth@gmail.com - 17 Mar 2006 21:41 GMT
What's wrong with this?

if (bool)(UserIDs[i] == ThisUserId)
{
  return true;
}
eric.goforth@gmail.com - 17 Mar 2006 21:44 GMT
There's a closing "}", it's inside a function.

if (bool)(UserIDs[i] == ThisUserId)
{
  return true;
}
eric.goforth@gmail.com - 17 Mar 2006 21:45 GMT
private bool validateUserId(string ThisUserId, string[] UserIDs)

if (bool)(UserIDs[i] == ThisUserId)
{
  return true;
}
AlanT - 17 Mar 2006 21:49 GMT
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.
wfairl@gmail.com - 17 Mar 2006 21:51 GMT
there's no need for anything except return (UserIDs[i] == ThisUserID);
AlanT - 18 Mar 2006 17:56 GMT
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.
wfairl@gmail.com - 17 Mar 2006 21:49 GMT
I'm guessing you mean  if((bool) (UserIDs[i] == ThisUserId)) but the
explicit cast is redundant. What are the types of the variables listed?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.