Collection access errors that should not occur

Source: Internet
Author: User

When I wrote an Excel import program the day before yesterday, I had a small regret and wrote it for reference:
To verify the validity of the data, I add the valid data of the field to a set in sequence, traverse each value to be verified, and verify it using the Contain method of the set.
Unfortunately, for clearly valid values, verification is always passable. It's really anxious.
To find out the cause, I checked the type of the elements in the Set and the values to be verified. The types are also the same, and the comparison is equal, why can't the Contain method always fail? Only the BooleanValue = Object. Contain (key) style usage is displayed. I thought, that's strange. How can this problem be solved after a simple comparison?
Read carefully and find that the Contain method of the set is a comparison of key values. You must specify the key value when adding elements to the set. This method is used:
Object. Contain (Value, Key)
Comparison is a comparison of "healthy values". To facilitate direct comparison, you can use values as key values.
To check the valid gender, you must add the valid values male and female:
Object. Add ("male", "male ")
Object. Add ("female", "female ")
Then, you can use the Contain method to compare the values "male" and "female" in the not-in-set SEX.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.