Sign in to follow this  
jor1980

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

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this