which one is good:
string sQuery = \"SELECT * FROM table\";
or
const string sQuery = \"SELECT * FROM table\";
<
The latter is better - it means that:
There are some other effects of "const" in terms of access from other assemblies and versioning, but it looks like this is a private field so it shouldn't be an issue. You can mostly think of it as being:
static readonly string sQuery = ...;
In general I believe it's a good idea to make fields static when you can (if it doesn't vary by instance, why should it be an instance variable?) and read-only when you can (mutable data is harder to reason about). Let me know if you want me to go into the details of the differences between static readonly
and const
.