public void Order() { var lastName = BreakLine(NameList.GetName(), false); lastName.ReorderByAscending(); NameList.ReorderByAscending(); var newList = new DataSubstringList(); var newIndex = 0; foreach (var data in lastName.GetList()) { string newValue = null; var dataValue = lastName.GetList().Where(e => e.Value == data.Value).ToList(); //if has same last name if (dataValue.Count > 1) { newValue = NameList.GetList().Where(e => dataValue.Select(y => y.Order).Contains(e.Order) && !newList.GetList().Select(y => y.Value).Contains(e.Value)) .FirstOrDefault().Value; } else { newValue = NameList.GetNameAtIndex(data.Order); } if (newValue != null) { newList.Add(new DataSubstring(newIndex, newValue)); } newIndex++; } NameList = newList; }
private IDataSubstringList BreakLine(List <string> line, bool getFirstName) { var result = new DataSubstringList(); var index = 0; if (!getFirstName) { index = 1; } for (int i = 0; i < line.Count; i++) { var shards = BreakString(line[i]); result.Add(new DataSubstring(i, shards[index])); } return(result); }