Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Lets say There is a collection of Items
When item 1 added with type "grocery" more than 1 times then i need to show the popup icon on the basis of some boolean flag "isShowIcon = true/false".

when item 1 added with type "grocery" (no information popup icon)
when item 2 added with type "grocery" (show information popup icon)
when item 3 added with type "cosmetics" (no information popup icon)
when item 4 added with type "grocery" (show information popup icon)

Delete item 1 then
item 2 (no information popup icon)
item 4 (show information popup icon)

Delete item 2 then
item 4 (no information popup icon)

What I have tried:

I have tried several logic's but unable to accomplish the requirement.
Posted
Updated 15-Jul-18 15:25pm
v2

Before the new item is added, do something like this:


C#
var found = mycollection.FirstOrDefault(x=>x.name == text);
if (found == null)
{
    mycollection.Add(text);
}
else
{
    MessageBox.Show("Duplicate names are not allowed.");
}
 
Share this answer
 
v4
A System.Collections.Generic.HashSet<T> is typical for detecting duplicates. Basically, you do the following...

string text = "Some Text";

var mySet = new HashSet<string>();
if (mySet.Contains(text))
  Console.WriteLine("Duplicate!");
else
  mySet.Add(text);
 
Share this answer
 
v2

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