有一个接口OptionsSet和一个抽象类StringBasedOptionsSet。
interface OptionsSet {
string getString(string key);
int getInt(string key);
}
abstract class StringBasedOptionsSet : OptionsSet {
int getInt(string key) {
string v = getString(key);
try {
return Convert.ToInt32(v);
}
catch (Exception exc) {
if (exc is FormatException || exc is OverflowException) {
return 0;
}
throw;
}
}
}
为什么我不能调用getString(string)方法 from StringBasedOptionSet.getInt(string)?
csmade/StringBasedOptionsSet.cs(21,36): error CS0103: The name `getString' does not exist in the current context
csmade/StringBasedOptionsSet.cs(32,25): error CS0103: The name `getString' does not exist in the current context
我也尝试过调用OptionsSet.getString(key),base.getString(key)这导致非静态方法/对象不包含 getString错误的定义。
编辑:在剥离示例时,StringBasedOptionsSet没有实现接口是一个错误。OptionsSet它确实在我的实际代码中实现了接口。