只读修饰符和只读属性之间有什么区别吗?
示例:
public class GetOnly
{
public string MyProp { get; }
}
public class ReadOnly
{
public readonly string MyProp;
}
奖励:有没有一种方法可以创建一个适用于两者的接口?(与泛型一起使用)
public interface ISomething
{
public string MyProp { get; }
}
public class GetOnly : ISomething
{
public string MyProp { get; }
}
public class ReadOnly : ISomething // Cannot implement
{
public readonly string MyProp;
}
非常感谢您的提前帮助!