public static int CompareDinnerPlace(DinnerPlace d1, DinnerPlace d2) { if (d1.m_weight > d2.m_weight) { return(1); } else if (d1.m_weight < d2.m_weight) { return(-1); } else { return(0); } }
public DinnerPlaceManager(string filePath) { this.m_dinnerPlaces = new List <DinnerPlace>(); using (var r = new StreamReader(filePath)) { string line; while ((line = r.ReadLine()) != null) { string[] strings = line.Split('/'); DinnerPlace dPlace = new DinnerPlace(strings[0], Double.Parse(strings[1])); this.m_dinnerPlaces.Add(dPlace); } double sum = this.m_dinnerPlaces.Sum(m => m.m_weight); this.m_dinnerPlaces.ForEach(m => m.m_weight = m.m_weight / sum); this.m_dinnerPlaces.Sort(DinnerPlace.CompareDinnerPlace); } foreach (var m in this.m_dinnerPlaces) { m.printDinnerPlace(); Console.WriteLine(" "); } }