Jump to content
  • Advertisement
Sign in to follow this  
jor1980

If with an & operator between boolean and string [c#]

This topic is 2802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i would like to know if is it possible to make a & operator between a boolean value and a string value, something like this:

if(a==true & b=="high")

Share this post


Link to post
Share on other sites
Advertisement
In which language?

C++? Sure, you may want to use && instead of & though. And if by "string" you mean std::string instead of C strings.

Edit: nevermind, missed the C# in the topic.

Share this post


Link to post
Share on other sites
This is builtin behaviour. In C++ as well as C#, operator== returns a boolean value, either true or false. And boolean values can be combined using e.g. operator&&.

Share this post


Link to post
Share on other sites
i want that in my if a string was splitted and if the result array has 2 elements returns true. I have made this but i sends me an error:

if ((SubfileArray[listBox1.SelectedIndex].Name).Split('.')[1]==true)

Share this post


Link to post
Share on other sites
you may want to check if the "Length" property of that array is greater than one. the second element is not a boolean value, and if it was, this would still throw an error if your array has only one element (and you try to access the second one).

if ((SubfileArray[listBox1.SelectedIndex].Name).Split('.').Length > 1)

Share this post


Link to post
Share on other sites
Quote:
Original post by jor1980
i want that in my if a string was splitted and if the result array has 2 elements returns true.


Why not just check if the string contains the character you're splitting on? :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Quote:
Original post by jor1980
i want that in my if a string was splitted and if the result array has 2 elements returns true.


Why not just check if the string contains the character you're splitting on? :)


thank you, that must be the best way

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!