471,627 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

reflection, access the field of object dynamically


Let say I have an instance of class, eg. ArrayList. And assume that I
don't what properties are inside this instance/class. As I know I can
use Reflection to get the properties.

Now, assume that I got the properties programmatically, let them be
Count and Capacity.

How can I access the Count and Capacity for this 'instance',?


Feb 23 '06 #1
2 1491
>How can I access the Count and Capacity for this 'instance',?


Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 23 '06 #2
Or, more fully:

PropertyInfo countPi = instance.GetType().GetProperty("Count");
int count = (int)countPi.GetValue(instance);

Feb 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Freddy Willockx | last post: by
2 posts views Thread by Luis Arvayo | last post: by
5 posts views Thread by =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?= | last post: by
5 posts views Thread by DesCF | last post: by
17 posts views Thread by raylopez99 | last post: by
1 post views Thread by XIAOLAOHU | last post: by

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.