Metrics are calcucated using Visual Studio.
First method has CC = 4
private IEnumerable<string> GetRows(DataTable dt, string columnDelimiter)
{
return from DataRow row in dt.Rows
select string.Join(columnDelimiter, row.ItemArray.Select(k => k.ToString()));
}
Second method has CC = 5.
private IEnumerable<string> GetRowsForeach(DataTable dt, string columnDelimiter)
{
var rows = new List<string>();
foreach (DataRow row in dt.Rows)
{
var rowString = string.Join(columnDelimiter, row.ItemArray.Select(k => k.ToString()));
rows.Add(rowString);
}
return rows;
}
I'd say that first method should have CC = 1 and second maybe CC = 1 or maybe 2 (understanding foreach as for with end condition. But I would never say their CC is so high. What am I misunderstanding?