OK, this type of code I see every where. Many of us write this code every day.
Take a look at this below code?
// Create new instance of a DataSet
DataSet ds = new DataSet();
// Get data from a database
ds = GetData();
// Display Data
DataGrid1.DataSource = ds;
Now what is wrong with this above code? Absolutely nothing. We are creating a DataSet, filling it by calling a method GetData and binding it to a DataGrid.
Now, what if I replace the above code with this one line?
DataGrid1.DataSource = GetData();
Now both code are doing exactly same thing but the problem with first code snippet is, it is creating a DataSet object, which is not required at all.
By using second code snippet, we not only reduced the size of code and file, we also avoided creating a new DataSet object.
Still not clear? Let's think this way. I want to eat a Donut. In first case, I go to Dunkin Donuts, buy a donut, put in a plate and eat it. In second case, I buy a donut and direct eat it. In second case, not only I avoided use of a plate, I also avoided the execution time taken between dount and plate and plate and my mouth :-). Remember, every time you define a variable, somewhere, memory space is being allocated for that variable. No matter for how long you use it, it will still be extra overhead on the processor.
Here is one more example:
string str = "My String";
TextBox1.Text = str;
It can easily be replaced with this:
TextBox1.Text = "My String";
The second code is more efficient than the previous one.
Cheers!

Nagaraj SPosted Sep 12, 2015, 9:27 AM
Superb explanation
Nitesh KejriwalPosted Apr 18, 2014, 1:17 PM
Reading this article from the link of"becoming a C# programmer" and I am amazed this holds true for many so called programmers today as well
kumar Kashyap PandeyPosted May 5, 2013, 1:04 AM
Sir, You write complex articles but also write small things but essential to common developer. Touch every generation developer. One time you are legend another time down towards. You are great.
Mahesh ChandPosted May 28, 2007, 9:39 AM
Cheers!
Kapil DhawanPosted May 24, 2007, 8:54 AM
Generally developers follow the same thing. This is a better idea to write better code Thanks Mahesh !!!