private void btnGetGoalDiff_Click(object sender, EventArgs e) { try { string result = string.Empty; ReadExcel readExcel = new ReadExcel(); string csv_file_path = ConfigurationManager.AppSettings["FilePath"]; DataTable dt = readExcel.ReadCsvFile(csv_file_path); var datarows = dt.AsEnumerable().Where(row => row.ItemArray.All(o => !string.IsNullOrEmpty(o.ToString()))); var matchScoreDetails = datarows.Select(datarow => new MatchScoreDetails() { Team = datarow[(int)Enums.ScoreExcelFileColumnIndex.Team].ToString(), TotalMatches = Convert.ToInt32(datarow[(int)Enums.ScoreExcelFileColumnIndex.TotalMatches]), Won = Convert.ToInt32(datarow[(int)Enums.ScoreExcelFileColumnIndex.Won]), Loss = Convert.ToInt32(datarow[(int)Enums.ScoreExcelFileColumnIndex.Loss]), Draw = Convert.ToInt32(datarow[(int)Enums.ScoreExcelFileColumnIndex.Draw]), GoalFor = Convert.ToInt32(datarow[(int)Enums.ScoreExcelFileColumnIndex.GoalFor]), GoalAgainst = Convert.ToInt32(datarow[(int)Enums.ScoreExcelFileColumnIndex.GoalAgainst]), points = Convert.ToInt32(datarow[(int)Enums.ScoreExcelFileColumnIndex.Points]), }).ToList(); bool isValid = validateStructure(matchScoreDetails); if (isValid) { var lowestScore = matchScoreDetails.Where(c => (c.GoalFor - c.GoalAgainst) >= 0).Min(c => (c.GoalFor - c.GoalAgainst)); var winner = (from k in matchScoreDetails where ((k.GoalFor - k.GoalAgainst) == lowestScore) select k.Team).FirstOrDefault(); result = Constants.WinnerTeam + winner.ToString(); } else { result = Constants.ErrorMessage; } lblMessage.Text = result; } catch (CustomException) { throw new CustomException(string.Format(Constants.ErrorMessage)); } catch (Exception ex) { lblMessage.Text = ex.Message; } }