I have scenario like below
public abstract class Test
{
public string name;
public abstract bool is_selected();
}
public class Campus : Test
{
}
Now Campus must and should implement is_selected() method otherwise it throws an error. Adding to the same lines I want 'name' field also like that. I mean name field must be given a value.
How can I do that? Any help greatly appreciated.
Thanks in advance :)
I can find two options
public abstract class Test
{
public string name;
protected Test(string name){ this.name = name; }
}
public class Campus : Test
{
public Campus() : base("Init the name here") {}
}
public abstract class Test
{
public abstract string name { get; }
}
public class Campus : Test
{
public override string name => "name";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.