class instead of elseif

public class DiceResult { private int Min { get; set; } private int Max { get; set; } private string Name { get; set; } private static List<DiceResult> categories = new List<DiceResult>() { new DiceResult(){ Min = 01, Max = 35, Name = "Urban"}, new DiceResult(){ Min = 36, Max = 50, Name = "Rural"}, new DiceResult(){ Min = 51, Max = 75, Name = "Wild"}, new DiceResult(){ Min = 76, Max = 85, Name = "Wild Birds"}, new DiceResult(){ Min = 86, Max = 100, Name = "Zoo"} }; public static string GetCategories(int currentValue) { var result = categories.FirstOrDefault(m => m.Min <= currentValue && m.Max >= currentValue); return result.Name; } private static List<DiceResult> urban = new List<DiceResult>() { new DiceResult(){ Min = 01, Max = 25, Name = "Dog"}, new DiceResult(){ Min = 26, Max = 45, Name = "Cat"}, new DiceResult(){ Min = 46, Max = 50, Name = "Mouse"}, new DiceResult(){ Min = 51, Max = 55, Name = "Rat"}, new DiceResult(){ Min = 56, Max = 60, Name = "Pet Rodent (Guinnea Pig / Hamster)"}, new DiceResult(){ Min = 61, Max = 65, Name = "Squirrel"}, new DiceResult(){ Min = 66, Max = 75, Name = "Sparrow"}, new DiceResult(){ Min = 76, Max = 83, Name = "Pigeon"}, new DiceResult(){ Min = 84, Max = 85, Name = "Pet Bird (Parakeet Budgie)"}, new DiceResult(){ Min = 86, Max = 88, Name = "Bat"}, new DiceResult(){ Min = 89, Max = 92, Name = "Turtle"}, new DiceResult(){ Min = 93, Max = 96, Name = "Frog"}, new DiceResult(){ Min = 93, Max = 96, Name = "Monkey"}, }; public static string GetUrban(int currentValue) { var result = urban.FirstOrDefault(m => m.Min <= currentValue && m.Max >= currentValue); return result.Name; } }
(to help with my question on stackoverflow)
i'm wondering how to throw in lots more lists but just use the one method to return the result, rather than copying the same method for each list

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.