0
私はこの2つの方法のどちらかが他のものよりも優れていることを知りたいと思います。たとえば、アンボックス/ボクシングが必要ですか?または両方のunboxing/boxingが必要ですか?それらのうちのいずれかが他のものよりも優れているなら、どちらかといえば? IState
以来これらのアプローチのどちらが良いか、同じですか?
public interface IState
{
string Name { get; set; }
}
public sealed class FiniteStateMachine
{
private Dictionary<string, IState> allStates = new Dictionary<string, IState>();
public void AddState<TState>(TState newState) where TState : IState
{
allStates.Add(newState.Name, newState);
}
public void AddState(IState newState)
{
allStates.Add(newState.Name, newState);
}
}
public class EnemySoldierSword_TakingHitState : IState
{
public string Name { get; set; }
public EnemySoldierSword_TakingHitState(string name)
{
Name = name;
}
}
public class Program
{
public var FSM = new FiniteStateMachine();
FSM.AddState(new EnemySoldierSword_ChasingState("ChasingState"));
}
私は分かりますが、違いはありますが、この文脈では違いはありません。ありがとうございました。 – Lunatrap