c# and .NET :- What is covariance and contravariance in c# ?

Поделиться
HTML-код
  • Опубликовано: 19 дек 2024

Комментарии • 29

  • @dnfvideo
    @dnfvideo  3 года назад

    Do not miss our Interview Question video series
    30 Important C# Interview Questions : ruclips.net/video/BKynEBPqiIM/видео.html
    25 Important ASP.NET Interview Questions : ruclips.net/video/pXmMdmJUC0g/видео.html
    25 Angular Interview Questions : ruclips.net/video/-jeoyDJDsSM/видео.html
    5 MSBI Interview Questions : ruclips.net/video/5E815aXAwYQ/видео.html

  • @MrAfzalaziz
    @MrAfzalaziz 9 лет назад +6

    Covariance and Contravariance have been supported in prior versions in of .net. Actually .net 4.0 implements variance for generic interfaces and delegates using in and out key words. Note that for generic classes in .net 4.0, variance is NOT supported. ie List lstAnimal = new List(); will NOT compile.The video does not mention which feature is being introduced in .net 4.0 and which features it still has not implemented.

  • @jamesleo1498
    @jamesleo1498 8 лет назад +6

    Can you provide a link to the contravarience video you mention in this video? I'm having trouble locating it. Thanks!

  • @pradeep-vip
    @pradeep-vip 10 лет назад

    Covariance and Contra-variance have been a part of C# since 1.0 (.Net Framework 1.0) but earlier the parameters of methods used to be contra variant where as the return values used to be co-variant, with .Net 4.0 (with the introduction of 'in' and 'out' keywords it became possible to have both co-variant and contra-variant parameters for methods.

  • @pradeep-vip
    @pradeep-vip 10 лет назад

    Moreover to add some more to it Covariance and Contravariance define where an implicit cast can happen automatically and where you need an explicit cast (when it come to precompile behaviour.)

  • @shivkoirala
    @shivkoirala 11 лет назад +1

    @Rajesh kumar i have shown a actual demo that it is not working with previous version. Do you have any links or pointers to solidfy your statements.

    • @pradeep-vip
      @pradeep-vip 10 лет назад +3

      Covariance and Contra-variance have been a part of C# since 1.0 (.Net Framework 1.0) but earlier the parameters of methods used to be contra variant where as the return values used to be co-variant, with .Net 4.0 (with the introduction of 'in' and 'out' keywords it became possible to have both co-variant and contra-variant parameters for methods.
      Arrays of reference types, for example have always been been co-variant right from C# 1.0 so it is perfectly valid to do this:
      Animal[] cats=new Cat[10];
      but you would get a run-time exception if you try to do this:
      cats[0]=new Dog();
      Even if try to do this in C# 4.5 because arrays in CLR are mutable and hence need to preserve assignment compatibility.
      And this is what Rajesh Kumar Yanuganti meant to say.

  • @bhushan80
    @bhushan80 11 лет назад +1

    Where is next part which explains the contra variance? Thanks for the explanation of covariance.

  • @SwuaveWEB
    @SwuaveWEB 12 лет назад

    Yeah, i'm liking these videos. Keep up the good work. Subscribed.

  • @simonstanford1445
    @simonstanford1445 10 лет назад

    Very clear and concise - thank you!

  • @subashtamang2771
    @subashtamang2771 6 лет назад

    can you tell me what is code variant related to algorithms

  • @SAJJADAHMAD-uy3hu
    @SAJJADAHMAD-uy3hu 4 года назад

    Please keep your word. In this video you told to cover contravariance in next video but there is no next video of yours which covers contravariance.

  • @rameshnrkyoutubue
    @rameshnrkyoutubue 11 лет назад

    Thanks, excellent explanation.

  • @sumitrahulhotmail
    @sumitrahulhotmail 8 лет назад +3

    Please provide a link to the contravarience video

  • @prasadkhalane8606
    @prasadkhalane8606 3 года назад

    contravariance video link?

  • @MrKsackel12345
    @MrKsackel12345 7 лет назад

    great video. very clear

  • @yrajeshk532
    @yrajeshk532 11 лет назад +1

    The video kind of implies that the covariance and contravariance are introduced for the first time in .Net 4.0, which is wrong. This is only consolidated in 4.0. Some form of it was working since .Net 1.0. So this video is not accurate.

  • @mickeyp1291
    @mickeyp1291 11 лет назад

    but the array or list of these base clases is not compatible
    that is why Linq has Cast() extension method. but inl dot.net 4.0 that works. that's the point of the video.

  • @kel634
    @kel634 12 лет назад

    I get the idea, I just don't get when do you need this, can't you just use a new List of Animal-s?

  • @kianchristoffern
    @kianchristoffern 5 лет назад +2

    This is very good, but you (uploader) cheated so bad on explaining contravariance. "Contravariance is the opposite of Covariance."
    'Black is opposite of White' said the Master Painter. 'Now you know enough to paint.'
    Doesn't work with programming :D

  • @duranduran1223
    @duranduran1223 12 лет назад

    super.

  • @BackwardsDaveTV
    @BackwardsDaveTV 6 лет назад +1

    The title of this video is misleading. At no point do you explain contravariance in detail.

  • @bjarnenilsson80
    @bjarnenilsson80 Год назад

    Nice video, but you need to ber a pop filter, your plosives are rather distracting

  • @arpisaxena391
    @arpisaxena391 5 лет назад

    Where is contravariance??

  • @alex.rusnak
    @alex.rusnak 7 лет назад

    It's spelled 'kōˈve(ə)rēəns'.

  • @SAJJADAHMAD-uy3hu
    @SAJJADAHMAD-uy3hu 4 года назад +1

    Please keep your word. In this video you told to cover contravariance in next video but there is no next video of yours which covers contravariance.