【发布时间】:2013-10-04 13:11:31
【问题描述】:
有一个接口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;
}
}
}
为什么我不能从StringBasedOptionSet.getInt(string) 调用getString(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 接口是在剥离示例时出现的错误。它确实在我的实际代码中实现了接口。
【问题讨论】:
标签: c# interface abstract-class