Containing variable strings together, not generally used to connect the + strings, using the following two ways:
一、string.Format()
Second, the $ "" (available in more than six versions of C #, recommended such an approach)
. 1 public List <the Person> FindListByLastName ( String lastName)
2 {
. 3 the using (DB = the IDbConnection new new the SqlConnection (DbHelper.ConnectionString))
. 4 {
. 5 // Method one: Use string.Format (), write a string placeholder { 0}, followed by a variable
. 6 String SQL = String .Format ( " the SELECT * the FROM the Person the WHERE the lastName = '{0}' " , lastName);
. 7
. 8 // two: $ "", directly write variables in {}
. 9 String SQL = $ " the SELECT * the FROM the Person the WHERE the lastName = '{lastName}' ";
10
11 IEnumerable<Person> list = db.Query<Person>(sql);
12 return list.ToList();
13 }
14 }