C# IEnumerable (Generator) Explained

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

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

  • @MperAule
    @MperAule 4 года назад +7

    Golden RUclipsr. I only had to skip around in your videos to find what I needed - but damn. You go through everything so detailed. Big Thanks!

    • @RawCoding
      @RawCoding  4 года назад

      Thank you for watching ))

  • @vetald1979
    @vetald1979 4 года назад +6

    Great job. The reason for implementing two GetEnumerator() method one returning IEnumerator (prtty much IEnumerator ) and another IEnumerator is backward compatibility with Net 1.0 which did not support generics

  • @AK-we3gu
    @AK-we3gu 4 года назад +7

    Whole idea of LINQ Extensions methods works for classes which implements IEnumerable interface, so it is interesting to see how actually that iteration inside it works. Nice video, keep up the good work!

    • @RawCoding
      @RawCoding  4 года назад

      Thank you for watching))

  • @rolanddensonjr2464
    @rolanddensonjr2464 4 года назад +1

    Another great video here. You are on a roll with great content. Your delivery is spot -on and engaging.

  • @ruslankadyrkulov5747
    @ruslankadyrkulov5747 4 года назад +5

    Thank you for your videos, very informative and clear explanation.

    • @RawCoding
      @RawCoding  4 года назад

      Cheers :) glad you like them

  • @ЕгорБрызгалов-я4я
    @ЕгорБрызгалов-я4я 4 года назад +2

    And as always your explanation is the best:)

  • @toastyshrimp1882
    @toastyshrimp1882 3 года назад +1

    what is this Dump() method? is it part of LINQ? I can't seem to find anything about it anywhere and Rider throws a "can't resolve symbol" error when trying to use it despite importing the LINQ library. Also, the IEnumerable declaration also throws an error on the type, saying that IEnumerable doesn't have type parameters. Thanks for any help.

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

      It’s a LinqPad thing, LinqPad is the scripting tool I’m using

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

      @@RawCoding damn okay haha. I see pretty much every reply is you clarifying you're using LinqPad so I feel kind of bad that you're endlessly repeating yourself. Just not familiar with LinqPad so didn't know. Thanks.

  • @alfonsdeda8912
    @alfonsdeda8912 Год назад +1

    Hi, should i return from a method the IEnumerable interface or the concrete type? Thanks in advance.

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

      it depends on what you need. if you return IEnumerable without using the yield keyword no generator will be created. to put it simply IEnumerable represents something that create multiple values, be it they are already there on not there. If you need a collection of a known size use a list

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

      @@RawCoding Thanks for response, if I need to return database rows?

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

      Tell me what do you think? Hint “I don’t know” is not a good answer

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

      @@RawCoding Return values from database is considered a known number of object, right? So I can return a list?

  • @okcharles7
    @okcharles7 3 года назад +1

    Thank you, Anton.
    Recently, I have found that IList.Insert(0, element) was 10 ~ 30 times faster than IList.Add(element)?
    Does it relate to yield return?

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

      Don’t think so, yield return turns the function in to a generator you can’t add or insert in to a generator. For lists it depends how you tested it and what the implementation you’ve used.

    • @okcharles7
      @okcharles7 3 года назад +1

      @@RawCodingno special implementation. Just stored int numbers representing all cases of nCr , for example, 30C12.
      Actually, I prefer Array because I believe it consumes less memory.
      So, at first, I used arrays to store those cases but changed it into List which looks neater.
      At the time, I found IList.Add() is slightly faster than Array assignment.
      Later, I had to change the order where cases are stored so simply replaced IList.Add() with IList.Insert(0, x).
      then, I found IList.Insert(0, x) is much much faster than IList.Add().
      For example, when producing all the cases of 13C5, array takes around 0.22 seconds, IList.Add does it 0.03 seconds faster but IList.Insert does it in 0.007 seconds on my AMD Ryzen 7 2700U 2.20 GHz laptop.
      I used StopWatch instances to check the time. of course, those times changes at every execution but the speed difference always is apparent.

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

      List can have an implementation of a linked list or array list or immutable list - pint is there are many lists - insert at index means you say where to insert, without index the app has to perform an operation to find out, in a linked list it would have to iterate all the elements to append the element on the end.

    • @okcharles7
      @okcharles7 3 года назад +1

      ​@@RawCoding Many thanks, Anton. Then, it is true that IList.Insert has good benefit when the storing order doesn't matter.

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

      Yes

  • @chulaabey8331
    @chulaabey8331 4 года назад +1

    Awesome content. Best I've found.

  • @augischadiegils.5109
    @augischadiegils.5109 3 года назад +1

    What IDE are you using?

  • @youngking24
    @youngking24 4 года назад +1

    Maybe a dumb question but what are you programming in and why not visual studio?

    • @youngking24
      @youngking24 4 года назад +1

      Great explanation of ienumerable btw

    • @RawCoding
      @RawCoding  4 года назад

      It’s called LinqPad and it’s just way faster to run the program and easier to visualise

  • @astr0397
    @astr0397 3 года назад +1

    Man U are The Best Keep it Up :)

  • @charleswoodruff9013
    @charleswoodruff9013 4 года назад +4

    Not very well explained. Your example used in the first 7mins was confusing. Your examples are usually easier to follow.

    • @RawCoding
      @RawCoding  4 года назад

      Woudl you be able to explain why it's confusing?