private string GetUniqueName() { int newIndex = 0; FossilFuel fossilFuel; string fuelName; int index; string suffix; IList list = catalog.GetFossilFuelList(); for (int i = 0; i < list.Count; i++) { fossilFuel = (FossilFuel)list[i]; fuelName = fossilFuel.Name; if (!fuelName.StartsWith("Fuel ")) { continue; } index = "Fuel ".Length; suffix = fuelName.Substring(index); char[] chars = null; if (suffix != null) { chars = suffix.ToCharArray(); } bool suffixIsANumber = false; if (chars != null && chars.Length > 0) { suffixIsANumber = true; foreach (char c in chars) { if (!char.IsDigit(c)) { suffixIsANumber = false; break; } } } if (suffixIsANumber == true) { try { index = Int32.Parse(suffix); if (index > newIndex) { newIndex = index; } } catch (FormatException e) { Console.WriteLine(e.Message); } } } return("Fuel " + (newIndex + 1)); }
public object[] GetFossilFuelArray() { FossilFuelCatalog catalog = FossilFuelCatalog.Instance; return(catalog.GetFossilFuelList().ToArray(typeof(object)) as object[]); }