1. Its a more reliable method of determining if a column exists. By your
method what if you port your code to .Net 2.x and in the new version it does
not return null but instead it returns an empty column?
2. Its just better coding practice. It begs the question, why did Microsoft
bother giving you a Contains method? Think about it.
3. It also explicitly states your intentions, which is probably the most
important factor of all.
--
-Demetri
"RSH" wrote:
What is the difference? This appears to work as is outright.
"Lars-Inge Tønnessen (VJ# MVP)" <http://emailme.larsinge.com> wrote in
message news:u$**************@tk2msftngp13.phx.gbl... Please use the "Columns.Contains("column name")" method.
Example:
Lets say we have a DataGrid called "dataGridView1".
this.dataGridView1.Columns.Add("One", "One");
if (this.dataGridView1.Columns.Contains("One"))
System.Windows.Forms.MessageBox.Show("Yes");
this.dataGridView1.Columns.Add("Two", "Two");
this.dataGridView1.Columns.Add("Three", "Three");
Regards,
Lars-Inge Tønnessen
Siemens Medical - Norway