Is there any reason to use string.Format() with just a string parameter?

Cut and paste failures. Someone didn't take the time to cleanup the code. There is no reason to use string.Format. Simply delete it and assign directly.


⚠️ Warning ⚠️

If the person is using the Format to combine parameters be wary; one should use the SQLCommand and SQLParameter class to avoid sql injection.


While Format should be deleted, spare @ and make query being more readable:

  string query = 
     @"select type_cd, 
              type_shpmt 
         from codes";

If you want to modify table, field names etc. (which you can't do via Sql Parameters) try using string interpolation:

  string myTableName = "codes";

  ...

  string query = 
     $@"select type_cd, 
               type_shpmt 
          from {myTableName}";

Tags:

C#

.Net

Sql