Question by
brandoncluff · Dec 13, 2016 at 12:52 AM ·
c#listbestpracticesbest practices
Tracking Long Lists and Scalability
Hello!
I am wondering what the best method would be to track a list of 250 strings. I am wondering if I should be using SQLite or XML instead of List? What I'm currently doing doesn't seem that scalable.
private string AssignUnitName(Genders Gender) { string response; if (FemaleNames.Count == 0) { FemaleNames = ResetFemaleNames(); } if (MaleNames.Count == 0) { MaleNames = ResetMaleNames(); } if (Gender == Genders.FEMALE) { response = GetFemaleName(); RemoveFemaleName(response); } else /* Gender == Genders.MALE */ { response = GetMaleName(); RemoveMaleName(response); } return response; } private List<string> ResetFemaleNames() { List<string> response = new List<string>(); response.Add("Female Name 1"); response.Add("Female Name 2"); response.Add("Female Name 3"); return response; } private List<string> ResetMaleNames() { List<string> response = new List<string>(); response.Add("Male Name 1"); response.Add("Male Name 2"); response.Add("Male Name 3"); return response; } private string GetFemaleName() { string response = FemaleNames[UnityEngine.Random.Range(0, FemaleNames.Count - 1)]; return response; } private string GetMaleName() { string response = MaleNames[UnityEngine.Random.Range(0, MaleNames.Count - 1)]; return response; } private void RemoveFemaleName(string FemaleName) { FemaleNames.Remove(FemaleName); } private void RemoveMaleName(string MaleName) { FemaleNames.Remove(MaleName); }
I want one of the names to be chosen at random, and then for it not to be an option until all the other names have been used at least once. Doing it the way that I'm doing doesn't seem very smart. Help is appreciated!
Thank you.
Comment
Can you sort the list? $$anonymous$$aybe insert in alphabetical order can use the halving search (I forget it's name but some CS major will know it)