How to get the selected item index on a .NET ComboBox control?
I have a ComboBox
setup with 4 items, with indexes ranging from 0 to 3.
Later in my code, I need to do a certain event depending on what is selected. To do this I thought about comparing what the index of the selected ComboBox
item is, because integer comparison is faster than strings, right?
How can I get the index of the selected item开发者_StackOverflow社区?
ComboBox has a SelectedIndex property.
myComboBox.SelectedIndex
Regarding comparison:
If you're not doing millions of comparisons then this "optimization" wouldn't help you.
Are you sure that integer comparison is always faster than string comparison?
Depends how long the strings your comparing are... If you compare two strings that each only have one character then its a simple byte-wise AND operation which may be faster than comparing a 4 byte integer value.
精彩评论