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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:16:11+00:00 2026-05-27T00:16:11+00:00

Sorry if the tile is misleading. What i would like to do is to

  • 0

Sorry if the tile is misleading. What i would like to do is to use a string to get the values from a class. What i have:

class foo
{
    public string field1 {get;set;}
    public string field2 {get;set;}
}

public void run()
{
    //Get all fields in class
    List<string> AllRecordFields = new List<string>();
    Type t = typeof(foo);
    foreach (MemberInfo m in t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
    {
        AllRecordFields.Add(m.Name);
    }

    foo f = new foo();
    foreach(var field in AllRecordFields)
    { 
        //field is a string with the name of the real field in class
        f.field = "foobar";
    }
}

This a really simple example, so the problem is on the line f.field = "foobar";
The field is a string with a name of the real class field what i want to assignt the value to.

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

    Use PropertyInfo instead of MemberInfo and then SetValue.

    public void run()
    {
      foo f = new foo();
      Type t = typeof(foo);
    
      foreach (PropertyInfo info in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
      {
         info.SetValue(f, "foobar", new object[0]);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, I know this question is easy, but I don't know how to get
Sorry I am very new to open graph and have been having difficulty to
Sorry for the basic question. I have looked at other answers here on Stackoverflow
Sorry for some crazy subj. I'd like to override django models save method and
sorry for my english, I have a model named Recipe and Recipe has an
if I have tile in .png.tile. Is it possible to include it with .apk.
I'm making a platformer, with tile based map (like a lot of people). I
Sorry, if this sounds ignorant. Is it possible to SECURELY upload data from a
Sorry for the poorly-worded question. I was hoping to get everyone's ideas on the
Sorry if this is a noob question, but I have been given the dubious

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.