C# 如果选择了combobox中的特定对象,如何进行链接,然后执行某些操作

C# 如果选择了combobox中的特定对象,如何进行链接,然后执行某些操作,c#,indexing,combobox,C#,Indexing,Combobox,第一类 如何设置是否拾取了deformacijakore=“20%”,然后执行某些操作。。。 然后再次,如果10%,做与20%相同的“事情”。5%也一样 下面会写一些东西。。 提前谢谢你像这样的事 public static class DatabaseDeformacijaArmature { public static NovaDeformacijaArmature[] GetAllDeformacijaCelika() {

第一类

如何设置是否拾取了deformacijakore=“20%”,然后执行某些操作。。。 然后再次,如果10%,做与20%相同的“事情”。5%也一样

下面会写一些东西。。 提前谢谢你像这样的事

 public static class DatabaseDeformacijaArmature
        {
            public static NovaDeformacijaArmature[] GetAllDeformacijaCelika()
            {
                return new NovaDeformacijaArmature[]
                {
                     new NovaDeformacijaArmature
                     {
                         DeformacijaArmature = "20 %",
                         epsilonCelika = 20.0
                     },
                     new NovaDeformacijaArmature
                     {
                         DeformacijaArmature = "10 %",
                         epsilonCelika = 10.0
                     },
                     new NovaDeformacijaArmature
                     {
                         DeformacijaArmature = "5 %",
                         epsilonCelika = 5.0
                     }

                };
            }

Class 2

     var deformacijaCelika = DatabaseDeformacijaArmature.GetAllDeformacijaCelika();

                deformacijaCelikaComboBox.Items.AddRange(deformacijaCelika);


 private void deformacijaCelikaComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            NovaDeformacijaArmature selectedDeformacija = deformacijaCelikaComboBox.SelectedItem as NovaDeformacijaArmature;

                if 
       }
可选择使用该类:

private void deformacijaCelikaComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    double selected = ((NovaDeformacijaArmature)deformacijaCelikaComboBox.SelectedItem).epsilonCelika;

    if (selected == 20.0)
    {
        //do stuff
    }
    else if (selected == 10.0)
    {
        //do stuff
    }
    else if (selected == 5.0)
    {
        //do stuff
    }
}

你试过什么?那个代码做了什么?这和你想让它做的有什么不同?请阅读以获取有关为什么以及如何提供一个好的、最少的、完整的代码示例的建议。请阅读以获得如何以清晰、有用的方式表达您的问题的建议。@antestipe无需说谢谢,但您很高兴知道如何设置精度??像。。。a=某物,a'=某物。。。如何设置如果第三个小数点上的a=a,则为true@antestipe不知道是否有更简单的方法,但我倾向于做“如果(Math.Abs(a-b)<0.001)”
public class NovaDeformacijaArmature
{
    public double epsilonCelika { get; set; }

    public override string ToString() //This will be used when rendered by the combobox
    {
        return string.Format("{0:N0} %", epsilonCelika);
    }
}