这听起来可能很愚蠢,但...
当我创建大 SQL 命令时,我想让我的代码保持可读性,我这样做:
cmd.CommandText = "SELECT top 10 UserID, UserName " +
"FROM Users " +
"INNER JOIN SomeOtherTable ON xxxxx " +
"WHERE UserID IN (blablabla)";
看到串联了吗?现在,为了节省性能,我现在这样做:
cmd.CommandText = @"SELECT top 10 UserID, UserName
FROM Users
INNER JOIN SomeOtherTable ON xxxxx
WHERE UserID IN (blablabla)";
它使代码保持可读性,但节省了连接。现在它真的可以节省任何性能还是编译器足够聪明地“预先连接”第一个字符串?