Initialize list with both a single object and another list of objects

If the order of the elements is not important, you can use: List<MyObject> newList = new List<MyObject>(listOfObjects) { object1 }; This works by using the List<T> constructor which accepts an IEnumerable<T>, then the collection initializer to add the other items. For example, the following: static void Main() { int test = 2; List<int> test2 = … Read more

What benefits does dictionary initializers add over collection initializers?

While you could initialize a dictionary with collection initializers, it’s quite cumbersome. Especially for something that’s supposed to be syntactic sugar. Dictionary initializers are much cleaner: var myDict = new Dictionary<int, string> { [1] = “Pankaj”, [2] = “Pankaj”, [3] = “Pankaj” }; More importantly these initializers aren’t just for dictionaries, they can be used … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)