C# 将组合框成员值与字符串进行比较

C# Compare Combobox Member Value with string

我想将字符串与组合框成员值进行比较。如果字符串值匹配,我还需要匹配值的索引。

可能这会对你有所帮助。

private void SampleMethod()
{
    cboExample.Items.AddRange(new string[]
    {
        "Element 1", "Element 2", "Element 3", "Element 4"
    });

    string searchedText = "Element 3";
    int index = cboExample.FindString(searchedText);
    MessageBox.Show($"Index of \"{searchedText}\" is {index}");
}