Object Initialization can be simplified

  • Thread starter Thread starter MyCatAlex
  • Start date Start date
M

MyCatAlex

Guest
I have this code

using ( SqlConnection conn = new SqlConnection ( Globals.srv.ConnectionContext.ConnectionString ) )
{
conn.Open ( );
SqlCommand cmdm = new SqlCommand ( ); <== "message"
cmdm.Connection = conn;
cmdm.CommandType = CommandType.Text;

I noticed about two days ago that during debug the Visual Studio (2017, community edition) gives me aside from Errors and Warnings also so called "Messages." They are mostly, like: "Variable declaration could be inlined," and the one in the title. I got 675 such "messages" with 0 errors and 5 Warnings in my last debug. How will I correct the code above to make it simpler?

I also tried to comprehend the problem by reading this page, however I don't immediately see how it applies to my code. I do use "auto-implemented properties" in my C# code aplenty but those concern simpler properties, e.g int and string.

Thanks

Continue reading...
 
Back
Top