iab iab -4 years ago 146
C# Question

string format for long parameters

I am building a string using the string.Format method. Often, I will have very long parameter lists for tables with many columns for example

string query = string.Format("{0},{1},{2},...,{30}", val1, val2, ...., val30);


Does C# have a more concise way of dealing with such strings?

Answer Source

You can use string interpolation:

$"{val1},{val2},{val3}"

But I have to warn you: do not build the SQL statement using string.Format and alike. Use parameterized queries!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download