Why does IndexOf
fail to find last element in List
, for this code?
public List<Rule> rules = new List<Rule>();
Rule n = new Rule();
rules.Add(n);
Console.WriteLine(n == rules.Last<Rule>()); //True
dg_main.SelectedIndex = rules.IndexOf(n); //-1
Answer: Thank you all for your time. I was so confused with the situation that I didn't even saw that it wasn't IndexOf's fault. It was the dg_main.SelectedIndex who changed the index. DataGrid was sorted.
I think you have a mistake in the part of code which you didn't show, because code below works correct:
[Test, Explicit]
public void Test()
{
List<Rule> rules = new List<Rule>();
Rule n = new Rule();
rules.Add(n);
Assert.AreEqual(n , rules.Last());
Assert.AreEqual(0, rules.IndexOf(n));
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments