I have the following code:
var currentCity = db.City.Find(player.Location); switch (TravelTo) { case 1: costs = currentCity.TravelCost.City1; break; case 2: costs = currentCity.TravelCost.City2; break; case 3: costs = currentCity.TravelCost.City3; break; case 4: costs = currentCity.TravelCost.City4; break; case 5: costs = currentCity.TravelCost.City5; break; }
Is there a better way to get value? Is there a way to change the name of the string I want to call? So I could create something like
costs = currentCity.TravelCost.City[TravelTo]
Or something like that? I feel like I wrote an unnecessary switch statement, but my knowledge of C # is not good enough to come up with an alternative.
Thanks,
source share