Wednesday, July 13, 2011

Wasted Objects

Don't create objects unless you need them

Sad Code:
Dim MyTable As New DataTable 'Creates 1st data table

MyTable = MyFunction.GetDataTable()  'Destroys 1st data table and creates another

Happy Code:
Dim MyTable As DataTable

MyTable = MyFunction.GetDataTable()

Or if you prefer the quickie version:
Dim MyTable As DataTable = MyFunction.GetDataTable()