The right thing would be to transform this bunch of properties into a collection (array, list, or similar).
public class Teste
{
public List<int> Campos { get; } = new List<int>();
}
So you do not have to change the template every time you need a new field, and it seems to make a lot more sense.
To use, you can do this:
var obj = new Teste();
for(int i = 0; i <= 8; i++)
{
obj.Campos.Add(i);
}
See working in .NET Fiddle.
If you really can not do this, you'll have to use reflection, you'll basically need the method SetValue
of PropertyInfo
.
For example:
var obj = new Teste();
string propBase = "campo_";
for(int i = 1; i <= 8; i++)
{
var propName = propBase + i;
typeof(Teste).GetProperty(propName).SetValue(obj, i, null);
}
See working in .NET Fiddle.