I have a question about the C# 2008 statement listed below:
string[] PkgIDs = rData.details.Where(c => c.batch_id == batchID).Select(c => c.Package_ID).Distinct().ToArray();
foreach (string PkgID in PkgIDs)
{
}
I would want to make certain an excpetion would not be generated in this situation.
If there is nothing selected for the PKgIDs [] table, do I need to to any check for this condition? If so, what would the check be?
Would you show me what code I would need to add?
Loading
VulpesPosted Oct 7, 2012, 9:33 AM
foreach works without error on an empty array - the code in the body of the loop is simply never executed - so, an exception will not occur in these circumstances.
For extra reassurance, this program produces an empty array (there are no strings that start with "D") but there is no error and no output: