C
C#•2y ago
Pacrombie

Trying to learn about interfaces

Is the pseudocode shown in my image a practical use of interfaces?
15 Replies
Pobiega
Pobiega•2y ago
yep, thats how interfaces work. you don't need to specify public in the interface tho (for the method) void SomeMethod(); will have the same effect
Pacrombie
PacrombieOP•2y ago
interface methods are public by default?
Pobiega
Pobiega•2y ago
ye
Pacrombie
PacrombieOP•2y ago
sick, thank you can you have members in interfaces?
Pobiega
Pobiega•2y ago
you can have properties
Pacrombie
PacrombieOP•2y ago
ah ok
Pobiega
Pobiega•2y ago
I don't think you can have fields. I have never tried or wanted, in 20 years of coding C# 😄
Pacrombie
PacrombieOP•2y ago
and does the inheritor have to implement a body for the property?
ero
ero•2y ago
fields shouldn't be visible outside of the class :3
Pobiega
Pobiega•2y ago
for exactly this reason have I never tried
Pacrombie
PacrombieOP•2y ago
right
Pobiega
Pobiega•2y ago
well, tehy have to implement the prop - so at minimum they need to specify an autoprop with the same name and type
Pacrombie
PacrombieOP•2y ago
so should you pretty much always use properties to expose fields outside of a class?
Pobiega
Pobiega•2y ago
you can also specify in the interface { get; } but in the implementing class also have a setter, thats fine yes
Pacrombie
PacrombieOP•2y ago
got it thank you, ive been using these concepts without really understanding them and this helps a lot
Want results from more Discord servers?
Add your server