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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:41:29+00:00 2026-06-02T08:41:29+00:00

This is an interesting concept which i couldn’t figure out how to implement. (its

  • 0

This is an interesting concept which i couldn’t figure out how to implement. (its related to a university assignment where i need to deploy the decorator pattern).

I’ve written rough C# code below which won’t compile however, Suppose, i have a class

Class A {
   public int A { get; set; }
   public string B { get; set; }
   public float C { get; set; }

   public string concatFields() {
       string sample = null;
       foreach (Field f in this) {
           sample += f.ToString();
       }
       return sample;
   }
}

How in terms would you achieve the concatFields method? Is there a way to iterate through the class’s fields (without knowing the names of the fields) and call ToString() on each.

In example B scenario, how would you apply the same method on all Fields provided they were the same type.

Cheers guys for the help, i’ve tagged this with C# but not sure what other tags could be applied

  • 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-02T08:41:30+00:00Added an answer on June 2, 2026 at 8:41 am

    You can use reflection, iterate over metadata of your class, and pull fields through the reflection API. Obviously, there is a cost attached to that: using reflection is slower than accessing fields directly; sometimes, considerably. However, you can certainly do it. Here is an example:

    MyClass obj = new MyClass();
    // Set fields in the obj...
    var fields = typeof(MyClass).GetFields(System.Reflection.BindingFlags.GetField);
    StringBuilder res = new StringBuilder();
    foreach (FieldInfo f in fields) {
        var val = f.GetValue(obj);
        if (val != null) res.Append(val.ToString());
    }
    Console.WriteLine(res.ToString());
    

    FieldInfo class exposes many useful properties, such as Name and Type, letting you pick which fields to include in your processing, and which fields to ignore.

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

Sidebar

Related Questions

i have been reading this interesting article which is increasing my every growing confusion
I want to implement the concept of a Workspace. This is a global concept
I'm testing out an interesting threading concept in PHP. Basically, I'm working to have
I've just found this interesting presentation about the concept of object oriented CSS. It
there's this interesting problem i can not solve myself. I will be very glad,
I found this interesting site, that helps me understand derivatives, http://www.numberempire.com/derivatives.php , It seems
There is this interesting game, that has numbers in a grid, where each number
I recently came in contact with this interesting problem. You are given a string
In Matters Computational I found this interesting linear search implementation (it's actually my Java
As part of my ecommerce application, I have this interesting problem, I've been trying

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.