Get IndexOf item in NVL

Get IndexOf item in NVL

Old forum URL: forums.lhotka.net/forums/t/6135.aspx


Mudit posted on Tuesday, January 13, 2009

Hello,

    I have a NameValueLise of type <int,string>, i want to get the index of an item that is already there in the list

Csla.NameValueListBase<int, string>.NameValuePair newItem = new Csla.NameValueListBase<int,string>.NameValuePair(ID,VALUE));

int indexA = NVLIST.IndexOf(newItem);

but indexA always gets -1. The ID and VALUE assigned to newitem exist in the NVLIST.

can u guide why IndexOf is not able to get index of the item with ID and VALUE in NVLIST.

ajj3085 replied on Tuesday, January 13, 2009

Because the IndexOf is looking for the same object reference as something in the list, and the object you're passing to IndexOf is created via new and never added to the list.  It doesn't compare the Id or value.

I think you'll want GetItemByKey or GetItemByValue, and use the result of that to call Indexof.

Copyright (c) Marimer LLC