Вы можете использовать дополнительное закрытое поле, которое будет виртуальным, поэтому вы можете переопределить его в дочернем элементе.
Попробуйте это:
public interface IParent
{
string HelloWorld { get; }
}
public class Parent : IParent
{
protected virtual string World { get; }
public string HelloWorld
{
get
{
return "Hello " + World;
}
}
}
public class Children : Parent
{
protected override string World { get; } = "World";
}
Или вы можете также передать строку через конструктор, а затем установить значение во время выполнения.
public interface IParent
{
string HelloWorld { get; }
}
public class Parent : IParent
{
private readonly string world;
public Parent(string world)
{
this.world = world;
}
public string HelloWorld
{
get
{
return "Hello " + world;
}
}
}
public class Children : Parent
{
public Children(string world) : base(world)
{
}
}
Используйте это так:
var children = new Children("World");
Console.WriteLine(children.HelloWorld);