c# - Columns.Add() vs new DataColumn() -



c# - Columns.Add() vs new DataColumn() -

i sense confused on how insert new column on table, , what's difference between columns.add() , new datacolumn()?

datatable pupil = new datatable("students"); student.columns.add("id", typeof(int)); datacolumn id = new datacolumn("id"); id.datatype = typeof(int); student.columns.add(id);

datacolumncollection.add short-cut creating column , adding it. msdn says:

creates , adds datacolumn object has specified name , type datacolumncollection.

and how implemented:

public datacolumn add(string columnname, type type) { datacolumn column = new datacolumn(columnname, type); this.add(column); homecoming column; }

as can see, internally creates new instance of datacolumn , adds itself.

note: can utilize datacolumn constructor accepts column info type sec parameter. sec sample like:

student.columns.add(new datacolumn("id", typeof(int)));

but anyway, think first 'short-cut' alternative more readable , compact. might want utilize latter approach if have columns, or if have columns of custom type inherited datacolumn.

c# datatable ado.net

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -