You can do that by using a Dictionary<TKey, TValue>
.
A dictionary is a collection of keys and values. In your case you probably would like to use a Dictionary<string, LogClass>
then you can have something like this:
Assuming LogClass
is your class...
public class LogClass
{
public int CNLog { get; set; }
}
string a = "dig";
string b = "value";
dictionary[a].CNLog = 7;
dictionary[b].CNLog = 17;
But of course before doing that you would have to say what is the value that goes into dictionary[var]
.
dictionary[a] = new LogClass();
That is how you would use it, hopefully you will be able to adapt this solution to your code.
And you can check out a video that explains step-by-step very slowly and clearly how to work with it on Microsoft Virtual Academy: C# Fundamentas at 22:00.