0 Comments

Sometimes I need to do the same thing repeatedly as a part of my normal work tasks. For example, if I need to query a database using a list of strings I might need to escape all the strings in the list. LINQPad allows me to easily write some C# to do that and save the code to use again later. I will demonstrate this using my example of preparing a list of strings for a database query.

I might be given this list of ingredients and I need to use them in a SQL query.

flour

vinegar

eggs

sugar

cornmeal

I can write some C# code in LINQPad to take a string, split it at each newline, then combine it separating the values with commas.

StringToSQLINQuery

Now I can easily get the values I was given ready for a SQL query.

StringToSQLINQueryRan

So that I don’t have to write the same code again next time I will save it to my LINQPad queries folder.

StringToSQLINQuerySave

Now I can access that same code again next time easily.

StringToSQLINQuerySavedQueries

That’s all I have to do and I have a quick and easy way to do something repetitive. LINQPad is a great utility for small coding tasks.

Post comment