saunde Posted December 9, 2007 at 12:54 PM Report Share #153248 Posted December 9, 2007 at 12:54 PM 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 More sharing options...
falk0n Posted December 9, 2007 at 01:43 PM Report Share #153255 Posted December 9, 2007 at 01:43 PM pq o que tens de colocar dentro do foreach nao a e linked list mas sim o objecto que a linkedlist tem ou seja o request vou passar-te um link da microsoft: http://msdn2.microsoft.com/en-us/library/ttw7t8t6(VS.80).aspx http://msdn2.microsoft.com/en-us/library/9yb8xew9(VS.80).aspx boas programacoes Link to comment Share on other sites More sharing options...
saunde Posted December 9, 2007 at 03:24 PM Author Report Share #153262 Posted December 9, 2007 at 03:24 PM 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 More sharing options...
TheDark Posted December 11, 2007 at 02:33 AM Report Share #153565 Posted December 11, 2007 at 02:33 AM Estás a dar a volta ao assunto 🙂 Em vez de LinkedListNode<Request> tens que utilizar Request no foreach. Do modo como resolveste tens uma LinkedList de LinkedListNode, e não uma LinkedList de Request. Desaparecido. Link to comment Share on other sites More sharing options...
saunde Posted December 14, 2007 at 08:58 PM Author Report Share #154343 Posted December 14, 2007 at 08:58 PM Fixe! funciona 😄 Eu pensava que não funcionava visto a class Request não implementar IEnumerable tás a perceber ? Um blog :Sem Cafeína Link to comment Share on other sites More sharing options...
TheDark Posted December 15, 2007 at 01:25 AM Report Share #154367 Posted December 15, 2007 at 01:25 AM Sim, mas o que tem que implementar IEnumerable é o contentor 😄 Desaparecido. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now