P
P
Pixilys2020-02-26 14:54:08
C++ / C#
Pixilys, 2020-02-26 14:54:08

It is not known how many fields will be in the class?

A common example of a person class with a Name field

class Person
    {
        private string name;

        public string Name { get => name; set => name = value; }
    }

And tomorrow it will be necessary to add a birthday, and then what is your mother's name, well, etc.
I'm sure that this is all done, but as a beginner I don't know what it's called and what to look for.
Let the list of fields be saved in settings.
And how it is possible to make that created fields, having received the list.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-02-26
@Pixilys

public class Person
{
    private Dictionary<string, string> prop = new Dictionary<string, string>();

    public void SetProp(string key, string value)
    {
        prop[key] = value;
    }

    public string GetProp(string key)
    {
        return prop[key];
    }
}

    public void Test()
    {
        Person pers = new Person();
        pers.SetProp("name", "Ivanov");
        var name = pers.GetProp("name");
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question