public string getRandomString (TextCategory category) { try { switch (category) { case TextCategory.hate: return Hate [random.Next (0, Hate.Count)]; case TextCategory.neutral: return Neutral [random.Next (0, Neutral.Count)]; case TextCategory.nice: return Nice [random.Next (0, Nice.Count)]; case TextCategory.random: return getRandomString ((TextCategory)random.Next (1, 4)); } } catch (ArgumentOutOfRangeException) { Console.WriteLine ("A needed Textcategory is empty, the programm may not behave properly"); } return "Internal error."; }
public List<string> GetTexts (TextCategory category) { List<string> texts = new List<string> (); var getTexts = from x in xmlhelper.xml.Elements ("category") where x.Attribute ("id").Value == ((int)category).ToString () select x.Elements ("text").ToArray (); foreach (XElement s in getTexts.First()) { texts.Add (s.Value); } return texts; }