开发者

How to get the selected item index on a .NET ComboBox control?

开发者 https://www.devze.com 2022-12-19 22:12 出处:网络
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 ind

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消