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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:45:54+00:00 2026-05-15T02:45:54+00:00

This is kind of hard to explain, so bear with me. In PHP, if

  • 0

This is kind of hard to explain, so bear with me.

In PHP, if you wanted create a new property in a class, you could without doing anything. The following code would work perfectly.

    class testClass
{
    public function __construct()
    {
    }
}

$test = new testClass;
$test->propone = "abc";
echo $test->propone;

I would like to do the same thing, only in C# and with a struct. Is this possible?

Yes, I know, this sounds really clunky. I am trying to simulate a sort of associative array, where there is none. In my environment (NET Microframeworks), hashtables and dictionaries are not supported (yet).

Thanks!

  • 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-15T02:45:55+00:00Added an answer on May 15, 2026 at 2:45 am

    As far as I know there’s no way to add properties dynamically at runtime. Nor is there a way to add properties at compile-time aside from adding them directly to the declaration. In my opinion, this is good as it maintains the type-safety expected from C#.

    However, couldn’t you make a primitive hashtable using List<KeyValuePair<int, List<KeyValuePair<string, object>>>> and String.GetHashCode()? Something like the following (untested and part-pseudocode, but you get the idea):

    class HashTable<T>
    {
        private List<KeyValuePair<int, List<KeyValuePair<string, T>>>> _table = 
            new List<KeyValuePair<int, List<KeyValuePair<string, T>>>>();
    
        private void Set(string key, T value)
        {
            var hashcode = key.GetHashCode();
            List<KeyValuePair<string, T>> l;
            if(!_table.TryGetValue(hashcode, out l))
            {
                l = new List<KeyValuePair<string, T>>();
                _table.Add(hashcode, l);
            }
    
            T o;
            if(l.TryGetValue(key, out o))
            {
                if (o != value)
                    l.Single(x => x.Key == key).Value = o;
            }
            else
                l.Add(new KeyValuePair(key, value));
        }
    
        private T Get(string key)
        {
            List<KeyValuePair<string, T>> l;
            object o;
            if(!(_table.TryGetValue(hashcode, out l) && 
                !l.TryGetValue(key, out o)))
            {
                throw new ArgumentOutOfRangeException("key");
            }
    
            return o;
        }
    }
    

    The following should help you with TryGetValue:

    public bool TryGetValue<TKey, TValue>(this List<KeyValuePair<TKey, TValue>> list, 
        TKey key, out TValue value)
    {
        var query = list.Where(x => x.Key == key);        
        value = query.SingleOrDefault().Value;
        return query.Any();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is kind of hard to explain, I hope my English is sufficient: I
This is kind of hard to explain, so I'll do my best: I want
This is kind of hard to explain. I have an absolutely positioned floating secondary
This is kind of hard to explain but I'll do what I can. I
it's pretty simple but is kind of hard to explain. I have this image
This is kind of hard to explain. Basically it's kind of like a simple
This is kind of hard to explain. Here's an example of my HTML: <div
So this is kind of hard to explain in text, I have attached an
This is kind of hard to explain, so i'll try the best I can
This is kind of hard to explain, but here is my problem: When, at

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.