c# - Lazy or not to use the new keyword without assigning the result? -


i enjoy learning new approaches , coding methods. question relates use of "new" keyword. 1 consider using new keyword without assignment fair practice?

   var example1 = new item();    example.add(testobject);  //ok     //using initializer ...    var example2 = new item    {        title= "this title",        summary = "this summary"    }; //fine again ..      //but question relates using new keyword ...       new item().add(testobject); 

i not keen on last approach, me seems little lazy , messy haha, there drawbacks or issues associated using new keyword in manner? don't think there garbage collector clean little advice here?

as quick example, when such approach used:

new databaseconnection().executesinglequeryandforgetaboutdb(...); 

so, if small utility oneliner work


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -