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 8244545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:53:19+00:00 2026-06-07T21:53:19+00:00

If I have a class object A, and it has properties such as a0,

  • 0

If I have a class object A, and it has properties such as a0, a1, a2… If this class has 100 properties like this (up to a99). I would like to display each of these properties, but I do not want to have 100 lines of code of calling this as following

print A.a0
print A.a1
print A.a2
...
print A.a99

The code is too inefficient, so I am wondering if there is a way to loop through these properties. Thank you.

  • 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-07T21:53:21+00:00Added an answer on June 7, 2026 at 9:53 pm

    .NET provides the ability to examine an object at runtime through a process known as reflection. The purpose of the original post was to iterate through an object’s properties in an automated fashion rather than by manually coding explicit statements that displayed each property, and reflection is a process to accomplish this very thing.

    For this particular purpose, looping through an object’s properties at run-time, you use the GetProperties() method that is available for each Type. In your case, the Type you want to “reflect” is A, so the type-specific version of GetProperties returns a list of the instance properties for that object.

    When you ask .NET to return the properties of an object, you can also specify what’s called a binding flag that tells .NET which properties to return – public properties, private properties, static properties – a myriad of combinations from about twenty different values in the BindingFlags enumeration. For the purposes of this illustration, BindingFlags.Public will suffice, assuming your A0-A999 properties are declared to be public. To expose even more properties, simply combine multiple BindingFlag values with a logical “or”.

    So, now armed with that information, all we need to do is create a class, declare its properties, and tell Reflection to enumerate the properties for us. Assuming your Class A exists with property names A0-A999 already defined, here’s how you’d enumerate ones starting with “A”:

    // Assuming Class "A" exists, and we have an instance of "A" held in 
    // a variable ActualA...
    using System.Reflection
    
    // The GetProperties method returns an array of PropertyInfo objects...
    PropertyInfo[] properties = typeof(ActualA).GetProperties(BindingFlags.Public);
    // Now, just iterate through them.
    foreach(PropertyInfo property in properties)
    {
        if (property.Name.StartsWith("A")){
        // use .Name, .GetValue methods/props to get interesting info from each property.
            Console.WriteLine("Property {0}={1}",property.Name,
                                                 property.GetValue(ActualA,null));
        }
    }
    

    There you have it. That’s C# version rather than VB, but I think the general concepts should translate fairly readily. I hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of objects, all from the same class(ColorNum) Each object has
I have a class called Order which has properties such as OrderId , OrderDate
I have this method signature: List<ITMData> Parse(string[] lines) ITMData has 35 properties. How would
I have a Snake class, which has a pointer to a Controller class object.
I have an object class called BOM. It has a method, getChildItem() which returns
I have an object that has a child collection: class Person { public string
I have an object from a NSObject class that I call brand and has
I have a serializable Message class that has a Data As Object property that
I have an IEnumerable<Person> object. The Person class has a Designation property. I want
I have an array (items) of custom class objects (catalogItem) each catalogItem has various

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.