I have this inside of a do..while
:
yield return string.Join(",", arr) + "\n";
Why isn't the compiler complaining that not all of the code paths are returning a value?
The full code example is below:
public static IEnumerable<string> Convert(Stream stream)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(stream);
var csvContent = string.Empty;
do
{
while (reader.Read())
{
var arr = new List<string>();
for (int i = 0; i < reader.FieldCount; i++)
{
var cell = reader[i]?.ToString();
var format = reader.GetNumberFormatString(i);
if (format == "mm\\/dd\\/yyyy" || format == "M/d/yyyy")
{
cell = cell.Replace(" 12:00:00 AM", "");
}
if (format == "h\\:mm\\:ss AM/PM")
{
cell = cell.Replace("12/31/1899 ", "");
}
var processedCell = cell == null ? string.Empty : cell.Contains(",") ? "\"" + cell + "\"" : cell;
arr.Add(processedCell);
}
yield return string.Join(",", arr) + "\n";
}
} while (reader.NextResult());
}
There is no return
keyword as the last line!