473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

IList-Items Retrieval

How to retrieve items from Ilist in .net 2.0?
Feb 13 '08 #1
4 1487
r035198x
13,262 8TB
How to retrieve items from Ilist in .net 2.0?
Have you checked the specs?
Feb 13 '08 #2
Hi,

I guess below example might b helpful to u..

public static Dictionary DataSourceToDictionary(object dataSource, string valueMember, string displayMember)
{
IList list = dataSource as IList;
Dictionary listLookup = new Dictionary();
if (list != null && list.Count > 0)
{
PropertyInfo valueMemberInfo = dataSource.GetType().GetGenericArguments()[0].GetProperty(valueMember);
PropertyInfo displayMemberInfo = dataSource.GetType().GetGenericArguments()[0].GetProperty(displayMember);
foreach (object item in list)
{
listLookup.Add(valueMemberInfo.GetValue(item, null).ToString(), displayMemberInfo.GetValue(item, null).ToString());
}
}
return listLookup;
}

Regards,
Sameer
Feb 13 '08 #3
Have you checked the specs?

yes.IList doesnot have the Item Property using C#.net VS 2005.so how to retrieve each of the item ?
Feb 13 '08 #4
Hi,

I guess below example might b helpful to u..

public static Dictionary DataSourceToDictionary(object dataSource, string valueMember, string displayMember)
{
IList list = dataSource as IList;
Dictionary listLookup = new Dictionary();
if (list != null && list.Count > 0)
{
PropertyInfo valueMemberInfo = dataSource.GetType().GetGenericArguments()[0].GetProperty(valueMember);
PropertyInfo displayMemberInfo = dataSource.GetType().GetGenericArguments()[0].GetProperty(displayMember);
foreach (object item in list)
{
listLookup.Add(valueMemberInfo.GetValue(item, null).ToString(), displayMemberInfo.GetValue(item, null).ToString());
}
}
return listLookup;
}

Regards,
Sameer
Thanks for the reply.when i try this code
i am getting an error like this:

"Using the generic type 'System.Collections.Generic.Dictionary<TKey,TValue >' requires '2' type arguments " while building
.

I am new to Dictionary,pls let me know how to make a call this function with thes 3 parameters..
Thanks in Advance
Feb 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: tsteinke | last post by:
I noticed somthing. The native Array Types implement the IList interface. However they do not contain all the methods in the interfaces they implement. for example... int test=new int;...
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
3
by: Chris | last post by:
Hi, the specs for System.Array are : public abstract class Array : ICloneable, IList, ICollection, IEnumerable but I can't use any of the functions presented by IList in my code ...
13
by: Sherif ElMetainy | last post by:
Hello I was just got VS 2005 preview, and was trying generics. I tried the following code int intArray = new int; IList<int> intList = (IList<int>) intArray; it didn't compile, also the...
13
by: cody | last post by:
why arent there some util functions for IList for example Sort()? -- cody Freeware Tools, Games and Humour http://www.deutronium.de.vu || http://www.deutronium.tk
2
by: Michael Groeger | last post by:
Hi, is it possible to determine if the PropertyType of a property support IList? We are inspecting all properties of a Type and we need to care about the properties which have a type which...
4
by: KC | last post by:
Could some one explain to me the casting rules for sending generic lists, ex. List<Person>, to a function that accepts List<object>? I cannot get the following easy-cheesy app to work. I get the...
2
by: Lucian Wischik | last post by:
Does ReadOnlyCollection<T> really implement IList<T>, like it claims to do? ... When I right-click on ReadOnlyCollection and look at its definition, it says this: public class...
6
by: Nick | last post by:
I have a code that returns data in IList. My webGrid doesn't allow me to sort with IList returned, it say it only suports DataView, DataTable and DataSet, not IEnumerable. I don't know how to...
6
by: nicolas.rolland | last post by:
Would anyone know the reson why IList<Tdoes not implements IList ?? This results in strange behaviours, like typeof(IList).IsAssignableFrom(typeof(List<string>)) --true...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.