Covariance and contravariance real world example

// Contravariance interface IGobbler<in T> { void gobble(T t); } // Since a QuadrupedGobbler can gobble any four-footed // creature, it is OK to treat it as a donkey gobbler. IGobbler<Donkey> dg = new QuadrupedGobbler(); dg.gobble(MyDonkey()); // Covariance interface ISpewer<out T> { T spew(); } // A MouseSpewer obviously spews rodents (all mice are // … Read more

C# Create New T()

Take a look at new Constraint public class MyClass<T> where T : new() { protected T GetObject() { return new T(); } } T could be a class that does not have a default constructor: in this case new T() would be an invalid statement. The new() constraint says that T must have a default … Read more

Parallel.ForEach vs Task.Factory.StartNew

The first is a much better option. Parallel.ForEach, internally, uses a Partitioner<T> to distribute your collection into work items. It will not do one task per item, but rather batch this to lower the overhead involved. The second option will schedule a single Task per item in your collection. While the results will be (nearly) … Read more

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