c# - Why is Task<T> not co-variant? -


class resultbase {} class result : resultbase {}  task<resultbase> getresult() {     return task.fromresult(new result()); } 

the compiler tells me cannot implicitly convert task<result> task<resultbase>. can explain why is? have expected co-variance enable me write code in way.

according someone may in know...

the justification advantage of covariance outweighed disadvantage of clutter (i.e. have make decision whether use task or itask in every single place in code).

it sounds me there not compelling motivation either way. itask<out t> require lot of new overloads, quite bit under hood (i cannot attest how actual base class implemented or how special compared naive implementation) way more in form of these linq-like extension methods.

somebody else made point - time better spent making classes covariant , contravariant. don't know how hard be, sounds better use of time me.

on other hand, mentioned cool have real yield return feature available in async method. mean, without sleight of hand.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -