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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:48:58+00:00 2026-05-26T19:48:58+00:00

I have the following class: public class foo { public Dictionary<string, string> data =

  • 0

I have the following class:

public class foo
    {
        public Dictionary<string, string> data = new Dictionary<string, string>();

        public foo(params object[] args)
        {
            foreach (object arg in args)
            {
                data.Add(arg.ToString(), "..");
            }
        }
    }

I need get the value of dictionary using the dot operadotor it’s because the class that I set the class as arguments use the dynamic keyword to “walk” on the class.

for example:

 var args = new[] {"a","b","c"};
 var Foo = new foo(args);
 var baa = Foo.data.a;
 Console.Write(baa); // .. 

if exists an way to make dynamic variables, something like:

public foo(params object[] args) {
foreach (object arg in args) {
  var name = (string) arg;
  var value = "..";
  MakeVariable(name, value);  
}
}

makes an variable named of arg and the value .. as public member of foo class.

anyway differents to solve this is very appreciated. Thanks in advance.

  • 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-26T19:48:58+00:00Added an answer on May 26, 2026 at 7:48 pm

    You can have Foo inherit from DynamicObject:

    public class Foo : DynamicObject
    {
        private Dictionary<string, string> data = new Dictionary<string, string>();
    
        public Foo(params object[] args)
        {
            foreach (object arg in args)
            {
                data.Add(arg.ToString(), "..");
            }
        }
    
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (data.ContainsKey(binder.Name))
            {
                result = data[binder.Name];
                return true;
            }
            return base.TryGetMember(binder, out result);
        }
    }
    

    To use it you can use dynamic to hold an instance of Foo:

    var args= new[] { "a", "b", "c" };
    dynamic foo = new Foo(args);
    var myA = foo.a; //returns ".."
    

    Keep in mind that you will lose type safety since you have to use dynamic – your use case should really justify this disadvantage – usually there is a better approach.

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

Sidebar

Related Questions

Basically, I have the following so far: class Foo { public override bool Equals(object
We have the following.. public class Foo { public string Name { get; private
I have the following: class Parent { public: virtual bool foo(vector<string> arg1, vector<string> arg2)
I have the following class: Class L{ public: bool foo(vector<bool> & data); private: C**
I have the following pojo: public class Foo { @Size(min=0,max=10) private String bar =
I have approximately the following picture: public class Foo { public Foo(Bar bar, String
If I have the following code: public class Foo { private Object obj =
Lets say I have the following: public class MyObject { [Bindable] public var foo:int
Is it possible to have something like the following: class C { public Foo
I have the following code: public class Foo {} static class Program { [XmlElement(foo)]

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.