Jump to content

foreach


saunde

Recommended Posts

Uma dúvida que é capaz de ser um pouco estúpida... mas está-me a fazer confusão....

Porque é que o foreach não funciona neste caso :

	private readonly LinkedList<Request> queue;

	public Matcher()
	{
		queue = new LinkedList<Request>();
	}


        	[MethodImpl(MethodImplOptions.Synchronized)]
	private LinkedListNode<Request> GetRequestByKey(int key)
	{
		if (queue.Count == 0) return null;

                    foreach (LinkedListNode<Request> Node in queue) {
                             if (Node.Value.Key == key) return Node;
                  }	 
                return null;
        }

LinkedList<T>  implementa IEnumerable e tudo.... devia dar para o foreach, ou estou errado ?

LinkedList is a general-purpose linked list. It supports enumerators and implements the ICollection interface, consistent with other collection classes in the .NET Framework.

LinkedList provides separate nodes of type LinkedListNode, so insertion and removal are O(1) operations.

Já agora fica aqui o erro também :

Error 1 Cannot convert type 'alinea_2.Matcher.Request' to 'System.Collections.Generic.LinkedListNode<alinea_2.Matcher.Request>'

Um blog :Sem Cafeína

Link to comment
Share on other sites

Mas o que eu estava a passar não era a LinkedList , era LinkedListNode, ou seja, um nó da LinkedList.

Mas já resolvi o problema.... foi só mudar a declaração e construção da Lista..

private readonly LinkedList<LinkedListNode<Request>> queue;

	public Matcher()
	{
		queue = new LinkedList<LinkedListNode<Request>>();
	}

Um blog :Sem Cafeína

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.