IndexOf can't find last element in a List

Gytis S

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.

IL_Agent

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why can't I find a slash in indexOf with JavaScript?

From Dev

Recursively find nth to last element in linked list

From Dev

Find List<T> second to last element

From Dev

How to find second last element from a List?

From Dev

Can't find element in frame

From Dev

Can't find why this js/jQuery to list last 12 months generates "undefined" warning

From Dev

Lua string.find can't find the last word in a line

From Dev

Selenium can't find element

From Dev

How to find index of last element in list matching predicate?

From Dev

Find kth to last element of a singly Linked List recursively -Python

From Dev

How to find the second last indexof a value in a string?

From Dev

Find the last element in an array

From Dev

ScrollView can't show the last element

From Dev

Javascript: can't find element

From Dev

I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element

From Dev

I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element

From Dev

Find the 3rd last element in the Singly Link List - Algorithm

From Dev

In Perl, how can I find the last defined element in an array?

From Dev

How to find second last element from a List?

From Dev

Can't find element in frame

From Dev

:last selector doesn't find last element in jQuery

From Dev

Binary search to find last element in sorted list that is less then specific value

From Dev

indexOf can find null

From Dev

How to find the index of last element on list and add it to another

From Dev

Can't find an element by "querySelector"

From Dev

ScrollView can't show the last element

From Dev

checking if list element exists in TCL can't find it

From Dev

Can't find elements of element

From Dev

Why doesn't my binary search implementation find the last element?

Related Related

  1. 1

    Why can't I find a slash in indexOf with JavaScript?

  2. 2

    Recursively find nth to last element in linked list

  3. 3

    Find List<T> second to last element

  4. 4

    How to find second last element from a List?

  5. 5

    Can't find element in frame

  6. 6

    Can't find why this js/jQuery to list last 12 months generates "undefined" warning

  7. 7

    Lua string.find can't find the last word in a line

  8. 8

    Selenium can't find element

  9. 9

    How to find index of last element in list matching predicate?

  10. 10

    Find kth to last element of a singly Linked List recursively -Python

  11. 11

    How to find the second last indexof a value in a string?

  12. 12

    Find the last element in an array

  13. 13

    ScrollView can't show the last element

  14. 14

    Javascript: can't find element

  15. 15

    I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element

  16. 16

    I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element

  17. 17

    Find the 3rd last element in the Singly Link List - Algorithm

  18. 18

    In Perl, how can I find the last defined element in an array?

  19. 19

    How to find second last element from a List?

  20. 20

    Can't find element in frame

  21. 21

    :last selector doesn't find last element in jQuery

  22. 22

    Binary search to find last element in sorted list that is less then specific value

  23. 23

    indexOf can find null

  24. 24

    How to find the index of last element on list and add it to another

  25. 25

    Can't find an element by "querySelector"

  26. 26

    ScrollView can't show the last element

  27. 27

    checking if list element exists in TCL can't find it

  28. 28

    Can't find elements of element

  29. 29

    Why doesn't my binary search implementation find the last element?

HotTag

Archive