473,396 Members | 1,982 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.

how can i acquire the values of an anonymous collection of objects?

i have this code...

Expand|Select|Wrap|Line Numbers
  1.    List<Sample> list = new List<Sample>();
  2.             list.Add(new Sample("balloons"));
  3.             list.Add(new Sample("candies"));
  4.  
  5.             IEnumerable sample = list;
  6.  
  7.             Type type = sample.GetType().GetGenericArguments()[0];
  8.             FieldInfo[] fieldInfos = type.GetFields();
  9.             PropertyInfo[] propertyInfos = type.GetProperties();
  10.  
  11.             foreach (var x in sample)
  12.             {
  13.                 Type a = x.GetType();
  14.                 Console.WriteLine( a.GetField(fieldInfos[0].Name).GetValue(a));
  15.  
  16.             }
and i have this class

Expand|Select|Wrap|Line Numbers
  1.  class Sample
  2.     {
  3.         public string name;
  4.         public string Name
  5.         {
  6.             get { return name; }
  7.             set { name = value; }
  8.         }
  9.  
  10.         public Sample(string name)
  11.         {
  12.             this.name = name;
  13.         }
  14.     }
  15.  
i want to be able to display the contents of the anonymous IEnumerable even though i do not know its field names... can anybody help me?
Nov 12 '09 #1
0 1038

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

Similar topics

18
by: booner | last post by:
I have a form that when it loads I would like to highlight the values (from a DB) that have been selected in a multiple selection list (<select multiple="true">. function onLoad() {...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
7
by: Julie | last post by:
According to the documentation for the Acquire methods on the ReaderWriterLock class: -1 Infinite. 0 No time-out. > 0 The number of milliseconds to wait. ...
3
by: Jeremy Ames | last post by:
I have a form that contains two hidden values, among other controls. I was wondering, if I change these values in server script and immediately do a server.transfer, do these values get updated...
22
by: tshad | last post by:
If I am passing a variable by reference to another routine by reference, do I need to dereference first? string testString; .... FirstSub(ref firstString) { HandleString(ref firstString); ...
9
ADezii
by: ADezii | last post by:
There are basically 4 Methods that you can use to access the values of Fields in Recordsets. For the purposes of this demonstration, I'll be using a Table called tblEmployees, a Field named , and a...
0
by: saheli | last post by:
In my C# project i call a VB 6.0 .dll which in turn returns a load of information. Most of this information is readable. However, some of the information returned is of type VBA.CollectionClass. ...
10
by: Dmitriy V'jukov | last post by:
On 16 ÍÁÊ, 21:41, "Dmitriy V'jukov" <dvyu...@gmail.comwrote: According to definition, release operation on 'std::atomic_global_fence_compatibility' can only 'synchronize with' acquire...
5
by: Pukeko | last post by:
Hi, this is an array that is used for a dropdown menu. var imageArray = new Array( "ecwp://" + document.location.host + "/massey/images/massey/ massey_07_fullres.ecw", "ecwp://" +...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.