We all know that we can set the properties of the ADO.NET objects by 2 ways.. By passing parameters to the constructors. Consider the following code snippet that creates a newSqlConnection object
and sets the connection string by directly specifying the value of the property.
Above task can be performed by passing the connection string as a parameter to the constructor, see the code below.. By setting the properties directly by specifying values makes code readable and debugging simple when compared with passing parameters to the constructors. In some cases passing parameters to a constructor may provide an advantage to our application. In the case of DataView object, setting the values of the RowFilter and RowStateFilter properties directly results in creating an Index at least twice while creating the object and when the properties are set. In this scenario pass the values for the properties, as parameters to the constructors is the profitable approach. Happy Learning !!! Dim objSqlCon as new System.Data.SqlClient.SqlConnection()
objSqlCon.ConnectionString = "Data source=localhost;Database=Northwind;User ID=sa;Pwd="
Dim objSqlCon as new System.Data.SqlClient.SqlConnection()
objSqlCon.ConnectionString = "Data source=localhost;Database=Northwind;User ID=sa;Pwd="
Practically I feel there is no significant difference in the performance of both the approaches and the choice depends on the perception of every individual.
Properties Vs Constructor Parameters- A Closer Analysis
0 comments
Hide comments