This is a code snippet I found for a project I'm working on. The goal of this snippet is to create five string variables to be used in a SQL Server stored procedure that takes some input parameters, including these five. Essentially, the stored procedure searches a database table for entries that include at least one of these five strings within the Name column.
What I like most?
A possible solution using List:
const string _query = "gugu gaga";
public static void Main()
{
if(string.IsNullOrEmpty(_query)) return;
List myList = new List();
myList.AddRange(_query.Split(' ').ToList());
string c1 = myList.ElementAtOrDefault(0);
string c2 = myList.ElementAtOrDefault(1);
string c3 = myList.ElementAtOrDefault(2);
string c4 = myList.ElementAtOrDefault(3);
string c5 = myList.ElementAtOrDefault(4);
StoredProcedureCall(c1, c2, c3, c4, c5);
}