Hello,
I have an Enum and a Generic.List(Of Enum)
1 Public Enum Mode
2 Count
3 Day
4 Month
5 End Enum
How can I loop, in the generic list, from the last item that was added
to the first item that was added and remove the duplicated values.
For example, if I add the following items:
1 Dim gl As New Generic.List(Of Mode)
2 gl.Add(Mode.Count)
3 gl.Add(Mode.Month)
4 gl.Add(Mode.Day)
5 gl.Add(Mode.Count)
6 gl.Add(Mode.Day)
I want to remove the items added in 5 and 6 because they are repeated
and they were added last.
Thanks,
Miguel 2 12295
On 14 May, 14:42, shapper <mdmo...@gmail.comwrote:
Hello,
I have an Enum and a Generic.List(Of Enum)
1 Public Enum Mode
2 Count
3 Day
4 Month
5 End Enum
How can I loop, in the generic list, from the last item that was added
to the first item that was added and remove the duplicated values.
For example, if I add the following items:
1 Dim gl As New Generic.List(Of Mode)
2 gl.Add(Mode.Count)
3 gl.Add(Mode.Month)
4 gl.Add(Mode.Day)
5 gl.Add(Mode.Count)
6 gl.Add(Mode.Day)
I want to remove the items added in 5 and 6 because they are repeated
and they were added last.
Thanks,
Miguel
Miguel,
it might make more sense to restrict adding duplicates than to remove
them after adding.... http://msdn2.microsoft.com/en-us/library/ms132319.aspx
Look at the Example paragraph,.
hth,
OJ
I agree with OJ. However if there is a reason why you can not do this then a
way to remove duplicates from the list is sort the list with the sort
function and then call the RemoveAll function with a predicate that compares
the previous mode with the current mode shown below:
private static Mode temp;
private static bool RemoveDuplicate(Mode currentMode)
{
bool isDuplicate;
if (temp == currentMode)
{
isDuplicate = false;
}
else
{
isDuplicate = true;
}
temp = currentMode;
return isDuplicate;
}
list.sort();
list.RemoveAll(RemoveDuplicate);
"OJ" wrote:
On 14 May, 14:42, shapper <mdmo...@gmail.comwrote:
Hello,
I have an Enum and a Generic.List(Of Enum)
1 Public Enum Mode
2 Count
3 Day
4 Month
5 End Enum
How can I loop, in the generic list, from the last item that was added
to the first item that was added and remove the duplicated values.
For example, if I add the following items:
1 Dim gl As New Generic.List(Of Mode)
2 gl.Add(Mode.Count)
3 gl.Add(Mode.Month)
4 gl.Add(Mode.Day)
5 gl.Add(Mode.Count)
6 gl.Add(Mode.Day)
I want to remove the items added in 5 and 6 because they are repeated
and they were added last.
Thanks,
Miguel
Miguel,
it might make more sense to restrict adding duplicates than to remove
them after adding....
http://msdn2.microsoft.com/en-us/library/ms132319.aspx
Look at the Example paragraph,.
hth,
OJ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Shi Mu |
last post by:
I used the following method to remove duplicate items in a list and
got confused by the error.
>>> a
, , ]
>>> noDups='] ]
Traceback (most recent call last):
File "<interactive input>", line...
|
by: Adam Clauss |
last post by:
I ran into a problem a while back when attempting to convert existing .NET
1.1 based code to .NET 2.0 using Generic collections rather than Hashtable,
ArrayList, etc.
I ran into an issue because...
|
by: junky_fellow |
last post by:
Hi all,
I have a linked list in which each node is of follwoing type.
struct node {
struct node *fptr;
int data;
int flag; /* flag could be ORIG=1 or DUPLICATE=2 */
}
|
by: semedao |
last post by:
Hi,
I want to implement list of key-values that can be sort by 2 ways.
let's say that in the first step I wanted to make SortList based on Key = int index that cannot change and Value is another...
|
by: Sehboo |
last post by:
We have several generic List objects in our project. Some of them
have about 1000 items in them. Everytime we have to find something,
we have to do a for loop. There is one method which does the...
|
by: shapper |
last post by:
Hello,
I have an enum as follows:
Public Enum Feature
Title
Content
Date
Search
End
|
by: Doug |
last post by:
I have a generic list object with a property called,
"MarkedForDeletion". During the course of my processing, some of the
objects in the list will get this property set to true and so at the
end...
|
by: =?Utf-8?B?Sm9lbCBNZXJr?= |
last post by:
I have created a custom class with both value type members and reference type
members. I then have another custom class which inherits from a generic list
of my first class. This custom listneeds...
|
by: DNB |
last post by:
I am using generic in the following example.
But I can figure out how to remove an item in the collection??
Thanks
DNB
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |