How to use IndexOf() method of List<object>

前端 未结 6 1697
遥遥无期
遥遥无期 2020-12-29 01:08

All the examples I see of using the IndexOf() method in List are of basic string types. What I want to know is how to return the index of

6条回答
  •  难免孤独
    2020-12-29 01:46

    you can do this through override Equals method

    class Employee
        {
            string _name;
            string _last;
            double _val;
            public Employee(string name, string last, double  val)
            {
                _name = name;
                _last = last;
                _val = val;
            }
            public override bool Equals(object obj)
            {
                Employee e = obj as Employee;
                return e._name == _name;
            }
        }
    

提交回复
热议问题