Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
How to take a specific item from a collection without using query(Linq) and for loop.....
Posted
Comments
PSK_ 23-Aug-10 1:24am    
If you know the index in that case you can access it through it.
Ramya 2010 23-Aug-10 1:31am    
No ya...... Let us consider im having 5 elements in a list such as {3,6,8,2,9,1}.If i want 8 means,straight a way i have to take it,without using Linq and for loop...... Which means i need a minimum coding to get a specific item from a collection.
PSK_ 23-Aug-10 2:14am    
In that case you can define "indexer" on your collection. Accessing object by index should be more efficient than accessing it any other way.
Ramya 2010 23-Aug-10 7:56am    
Thanks a lot for ur help.... Indexer gives an exact solution for me.....

All your answers can be found here[^]
 
Share this answer
 
XML
List<int> coll = new List<int> { 3, 6, 8, 2, 9, 1 };
          int searchNo = 8;
          int result = coll.Find(delegate(int item)
          {
              return searchNo == item;
          });
          Console.WriteLine(result);
 
Share this answer
 
Comments
Ramya 2010 23-Aug-10 2:16am    
let us consider im storing collection of objects in a list.Each and every object stores persons Information.These objects wil contain a member variable called name.while searching for the specific person,i just give a Person name ,the collection has to return the corresponding persons object. And this has to be done without using for loop and without using Linq........
PSK_ 23-Aug-10 2:22am    
Thats what I am telling you, use indexers http://msdn.microsoft.com/en-us/library/2549tw02.aspx
Ramya 2010 23-Aug-10 2:27am    
ok....... Thanks a lot for ur help.

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