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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:00:09+00:00 2026-05-26T00:00:09+00:00

I have set of properties as follows: public string Foo1 {set;get;} public string Foo2

  • 0

I have set of properties as follows:

public string Foo1 {set;get;}
public string Foo2 {set;get;}
public string Foo3 {set;get;}
public string Foo4 {set;get;}
public string Foo5 {set;get;}
public string Foo6 {set;get;}
public string Foo7 {set;get;}
public string Foo8 {set;get;}
public string Foo9 {set;get;}
......
public string Foo50 {set;get;}

then i m iterating through a collection as follows:

foreach(var element in sortedCollection.Keys){
   if(element != null)
   // in this block I would like to assign the element to the properties above
   // ex:
   foo?? = sortedCollection[element];
   // ?? need to be replaced by index.
}

Is there an easy way to do this?

  • 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-05-26T00:00:10+00:00Added an answer on May 26, 2026 at 12:00 am

    I think a better design would be:

    public List<string> Foos { get; private set; }
    

    If you can’t change it, you could probably do something like:

    var type = typeof(MyCalss);
    int index = 1;
    foreach (var key in sortedCollection.Keys)
    {
       var value = sortedCollection[key];
       var prop = type.GetProperty("Foo" + index);
       if (prop != null) prop.SetValue(this, value, null);
    
       index++;
    }
    

    … of course with some error handling, and where this assumes this is a method within your class. Can you determine an index based on the values in your sortedCollection?

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

Sidebar

Related Questions

I have a property declared as follows: public decimal? MyProperty { get; set; }
The language shortcut public string Code { get; set; } saves a bit of
I have a class as follows Public Class Foo Private _Name As String <ShowInDisplay()>
You might have a set of properties that is used on the developer machine,
I have set break points on my attached properties SetXXX and GetXXX static methods.
I have a simple website with a master-page. To set properties to elements on
I have a class with a set of properties As given below. class ContactInfo
I need to set the properties of a class using reflection. I have a
I have a Rect object that I'd like to create and set its properties
I have some logic that depends upon two properties being set, as it executes

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.