Ich verwende Fahrer, um einen C# -Codus zu kompilieren. Ich bin ein Neuling bei C#, aber ich kenne Java ziemlich gut. < /P>
Code: Select all
public interface IHasValue {
int GetValue();
// interface method with implementation;
bool IsZero() => GetValue() == 0;
}
public class TestHasValue : IHasValue {
private int value;
public int GetValue() => value;
// Error: Cannot resolve symbol 'IsZero'
bool test1() => IsZero();
// Compiles fine
bool test2() => ((IHasValue) this).IsZero();
}
Meine Erwartung (basierend auf Java), da TesthasValue IhasValue implementiert, konnte ich einfach Iszero () und C# sehen, dass die Implementierung sehen würde in der Schnittstelle. Ich hatte nicht erwartet, eine Instanz von TesthasValue zum Schnittstellentyp zu zwingen.>