Answer the question
In order to leave comments, you need to log in
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; }
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question