Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:03:16+00:00 2026-06-17T06:03:16+00:00

In my code, I declare one ArrayList within a ParentClass public class ParentClass {

  • 0

In my code, I declare one ArrayList within a ParentClass

public class ParentClass {
...
public ArrayList hybridElem; 
...

and then using Reflection that runs off the ParentClass, I am able to successfully obtain FieldInfo for this ArrayList @ runtime.

Using that FieldInfo, I want to be able to add or read elements from the hybridElem.
I am able to obtain all relevant PropertyInfo of ArrayList such as .Item, .Count, .ToArray etc etc … and also obtain getters and setters for these properties.

Unfortunately, none of them are being successfully invoked because MethodInfo.Invoke expects Object reference to ArrayList

Any Solutions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:03:17+00:00Added an answer on June 17, 2026 at 6:03 am

    You can do it easily enough. However, as the comments rightfully stated, I suggest you to switch from ArrayList to a generic collection.

    var instance = new ParentClass();
    var fieldInfo = instance.GetType().GetProperty("MyList");
    var arrayList = fieldInfo.GetValue(instance) as ArrayList;
    var count = arrayList.Count;
    

    With:

    public class ParentClass
    {
        public ArrayList MyList { get; set; }
    
        public ParentClass()
        {
            MyList = new ArrayList();
        }
    }
    

    Alternatively, to adapt it to your class which uses a field (assuming that said field is initialized somewhere):

    var instance = new ParentClass();
    var fieldInfo = instance.GetType().GetField("hybridElem");
    var arrayList = fieldInfo.GetValue(instance) as ArrayList;
    var count = arrayList.Count;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SS 2005 if that I've seen sample code like DECLARE @restore =
How to declare a one to one relationship using Entity Framework 4 Code First
In following code, in the derived class from ArrayList we are using a method
Using SQLDeveloper 2.1.1.64, if you try typing the following code: DECLARE v_status_code NUMBER; v_status_text
I have a class template similar to the one that follows below that is
Today I found one interesting thing. I didn't know that one can't declare a
I have the following code: DECLARE @testDate date --SET @testDate=dateadd(wk, 5830, 0) SET @testDate='2011-09-26
This SQL Server 2005 T-SQL code: DECLARE @Test1 varchar; SET @Test1 = 'dog'; DECLARE
I've got the following sql code: declare @x xml set @x = '<ResultBlock> <MatchSummary
I want to consult SQL Server OR short-circuit Code: DECLARE @tempTable table ( id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.