How to iterate through Linked List

前端 未结 4 1492
挽巷
挽巷 2021-01-12 08:12

I have looked around and I can\'t really find an answer I can understand or it doesn\'t apply to me. I have this class:

class Node
{
    public int value;
           


        
4条回答
  •  难免孤独
    2021-01-12 08:46

    I know this is an old post, but this is what is popping up on google, and I do have a good alternative to the current best answer (not including the desired value condition)

    LinkedListNode list = new LinkedListNode();
    for(LinkedListNode node=list.First; node != null; node=node.Next){
        //do stuff
    }
    
    
    

    This version obviously uses a for loop and moves the variable declaration and increment to one line allowing you to condense and beautify your code.

    提交回复
    热议问题