try {} miss {}

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?

  1. try miss pattern: a smart way to avoid the using of List class
  2. No more than five words!: I imagine the developer struggling to decide the correct number of query words

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);

}

brucecandoli.it

🌐 Siti Web
🛒 E-Commerce
🖥️ Applicazioni Web/Desktop
e molto altro...

Mappa del sito

envelopecrosschevron-down linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram