Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody

I have this queue:

Queue<<string>> q1;

1.Is there any way that I make a q to avoid repeated elements when enqueing to it?
Can I set a special q1 property or sth?

2. If I dont do number 1, How can I omit the repeated elements from it
(if any)and update the q?

btw I couldnt use distinct() method because Im not familiar with this "IEnumerable".
Posted
Updated 20-Jan-11 23:48pm
v2

1 solution

Don't worry IEnumerable<> is just a Type, To which you can easily fetch element by element using foreach.

If you don't want to get a distinct result in IEnumerable then you can fetch it in anonymous variable and then iterate that using foreach like

var result = queue.Distinct(); 
foreach(string s in result)
{
}


Or Either way you want in List<String> then you can do following.

List<String> list = queue.Distinct().ToList<String>();
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Jan-11 14:33pm    
Correct - my 5.
Additionally, it should be noted that IEnumerable is supported anyway:

foreach(string s in queue) { /* use s */ }

Of course, it iterates all items. Not just distinct.
Sergey Alexandrovich Kryukov 21-Jan-11 14:36pm    
Also, this form of Distinct is for default comparison (how = is defined)
Use Distinct<t>(IEqualityComparer<t>) for custom.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900