C#: Specify that a function arg must inhert from one class, and implement an interface?
Posted
by Rosarch
on Stack Overflow
See other posts from Stack Overflow
or by Rosarch
Published on 2010-03-28T22:02:36Z
Indexed on
2010/03/28
22:13 UTC
Read the original article
Hit count: 136
I'm making a game where each Actor is represented by a GameObjectController
. Game Objects that can partake in combat implement ICombatant
. How can I specify that arguments to a combat function must inherit from GameObjectController
and implement ICombatant
? Or does this indicate that my code is structured poorly?
public void ComputeAttackUpdate(ICombatant attacker, AttackType attackType, ICombatant victim)
In the above code, I want attacker
and victim
to inherit from GameObjectController
and implement ICombatant
. Is this syntactically possible?
© Stack Overflow or respective owner