Find particular item in List by sending its key

Posted by Kumar_jay99 under C# on 12/5/2011 | Points: 10 | Views : 945 | Status : [Member] | Replies : 3
how can i find the particular value in list by seding its key.

For example suppose list have follwing key value pair.

list.add(101,jay)
list.add(102,vijay)
list.add(103,shaym)

Than we have design such method which retun name if we pass id anc vice versa.




Responses

Posted by: Kumar_jay99 on: 12/5/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,
we can find the particular list item by following code below

List<DirectoryConfig> list = new List<DirectoryConfig>(m_DirectoryList.Keys);
DirectoryConfig ds = list.Find(delegate(DirectoryConfig p) { return p.DirectoryName == "Jay" });

the above code gives me id for jay passing its name ie 101

List<DirectoryConfig> list = new List<DirectoryConfig>(m_DirectoryList.Keys);
DirectoryConfig ds = list.Find(delegate(DirectoryConfig p) { return p.DirectoryId == 101; });

the above code gives me name ie Jay by passing its code ie 101


Thanks




Kumar_jay99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeev.Shukla on: 12/5/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Kumar_jay99,
I think it is not allowed to add the given elements into List as you specified.
First you have to create a Dictionary and then add these elements and then go for searching.

If I am not correct, please revert...

Kumar_jay99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumar_jay99 on: 12/6/2011 [Member] Starter | Points: 25

Up
0
Down
hi
i m just giving an example man
its not proper.
but main thing is how to search not how to create.

thaks


Kumar_jay99, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response