C# Developers' Journal (original) (raw)

3:03p

**downcast in foreach It's funny that foreach() allows implicit downcast. For example,

private string GetDataField(string headerText) { foreach (BoundColumn col in MainGrid.Columns) { if (col.HeaderText == headerText) return col.DataField; } return string.Empty; }

works even though MainGrid.Columns is actually a collection of DataGridColumn, not BoundColumn.

(1 Comment |Comment on this)