Hi everyone,
There are two ways by which we can use objects in C#.
1) DataSet ds = new DataSet();
2) DataSet ds;
Can
anyone tell me what is the difference between these two. I know
logically, in the first one memory is allocated for that object and
constructors are called. But we are used to with both the ways of
creating the objects. Which is the correct way to create object and
what are the situations on which either of the two should be used. Its
very helpful if example is given with explanation.
Thanks
Pankaj
Loading
Pankaj SahasrabudhePosted May 29, 2008, 1:30 AM
Scott LyslePosted May 28, 2008, 8:54 AM
DataSet ds = new DataSet(); creates a new instance of the dataset.
DataSet ds; declares the variable but it is unassigned (no new instance exists yet)
private void button1_Click(object sender, EventArgs e)
{
DataSet ds;
ds.DataSetName = "Chuck";
DataTable dt = new DataTable();
ds.Tables.Add(dt);
}
private void button2_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.DataSetName = "Chuck";
DataTable dt = new DataTable();
ds.Tables.Add(dt);
}