Click here to Skip to main content
15,897,518 members
Home / Discussions / C#
   

C#

 
GeneralRe: find an item in list collection to add or update Pin
arkiboys21-Feb-11 4:52
arkiboys21-Feb-11 4:52 
GeneralRe: find an item in list collection to add or update Pin
_Erik_21-Feb-11 5:03
_Erik_21-Feb-11 5:03 
GeneralRe: find an item in list collection to add or update Pin
arkiboys21-Feb-11 5:07
arkiboys21-Feb-11 5:07 
GeneralRe: find an item in list collection to add or update Pin
_Erik_21-Feb-11 5:15
_Erik_21-Feb-11 5:15 
GeneralRe: find an item in list collection to add or update Pin
Luc Pattyn21-Feb-11 5:09
sitebuilderLuc Pattyn21-Feb-11 5:09 
GeneralRe: find an item in list collection to add or update Pin
_Erik_21-Feb-11 5:14
_Erik_21-Feb-11 5:14 
AnswerRe: find an item in list collection to add or update Pin
Luc Pattyn21-Feb-11 5:11
sitebuilderLuc Pattyn21-Feb-11 5:11 
AnswerRe: find an item in list collection to add or update Pin
#realJSOP21-Feb-11 6:03
professional#realJSOP21-Feb-11 6:03 
I might do it this way:

C#
public class MyCollection : List<MyItem>
{
    public bool AddUnique(MyItem newItem)
    {
        bool found = false;
        if (!this.Contains(newItem))
        {
            foreach (MyItem item in this)
            {
                if (item.MyProperty == newItem.MyProperty)
                {
                    found = true;
                    break;
                }
            }
        }
        else
        {
            found = true;
        }
        if (!found)
        {
            this.Add(newItem);
        }
        return found;
    }
}

".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997


GeneralRe: find an item in list collection to add or update Pin
Orcun Iyigun21-Feb-11 13:37
Orcun Iyigun21-Feb-11 13:37 
GeneralRe: find an item in list collection to add or update Pin
Pete O'Hanlon22-Feb-11 1:36
mvePete O'Hanlon22-Feb-11 1:36 
GeneralRe: find an item in list collection to add or update Pin
#realJSOP22-Feb-11 3:31
professional#realJSOP22-Feb-11 3:31 
QuestionAT commands in c# Pin
aeman21-Feb-11 3:30
aeman21-Feb-11 3:30 
AnswerRe: AT commands in c# Pin
Thomas Krojer21-Feb-11 5:40
Thomas Krojer21-Feb-11 5:40 
QuestionSetting scanner device property constants (WIA) Pin
Etienne_12320-Feb-11 23:57
Etienne_12320-Feb-11 23:57 
QuestionRS232 interfacing help Pin
wjbjnr20-Feb-11 23:56
wjbjnr20-Feb-11 23:56 
AnswerRe: RS232 interfacing help Pin
OriginalGriff21-Feb-11 0:05
mveOriginalGriff21-Feb-11 0:05 
AnswerRe: RS232 interfacing help Pin
Dalek Dave21-Feb-11 0:21
professionalDalek Dave21-Feb-11 0:21 
GeneralRe: RS232 interfacing help Pin
OriginalGriff21-Feb-11 0:54
mveOriginalGriff21-Feb-11 0:54 
GeneralRe: RS232 interfacing help Pin
wjbjnr21-Feb-11 10:50
wjbjnr21-Feb-11 10:50 
GeneralRe: RS232 interfacing help Pin
OriginalGriff21-Feb-11 21:51
mveOriginalGriff21-Feb-11 21:51 
Questionbuild a Dynamic code - c# 4.0 Pin
arkiboys20-Feb-11 23:17
arkiboys20-Feb-11 23:17 
AnswerRe: build a Dynamic code - c# 4.0 Pin
Thomas Krojer20-Feb-11 23:34
Thomas Krojer20-Feb-11 23:34 
AnswerRe: build a Dynamic code - c# 4.0 Pin
dasblinkenlight20-Feb-11 23:37
dasblinkenlight20-Feb-11 23:37 
AnswerRe: build a Dynamic code - c# 4.0 Pin
RobCroll21-Feb-11 2:40
RobCroll21-Feb-11 2:40 
GeneralRe: build a Dynamic code - c# 4.0 Pin
arkiboys21-Feb-11 4:42
arkiboys21-Feb-11 4:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.