インターフェイス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)
からメソッドを呼び出せないのはなぜ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
、例を削除する際の間違いでした。実際のコードにインターフェイスを実装しています。