C#: The Heap and the Stack

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ก.ย. 2024
  • When programming in C#, it is very important to understand the concept of the heap and the stack. Value types such as integers are stored on the stack. Object types are stored on the heap, with pointers to them stored on the stack. This video explains the heap and the stack with an example and a diagram and demonstrates the dangers that await you if you do not understand this concept.

ความคิดเห็น • 50

  • @Sashkobg97
    @Sashkobg97 หลายเดือนก่อน +1

    Finally an explanations for a dummies like me! Thanks you for this, huge upvote!

  • @yawnyawning
    @yawnyawning 2 ปีที่แล้ว +6

    so far the easiest explanation of stack and heap ive seen

  • @yasu3d
    @yasu3d 6 หลายเดือนก่อน +2

    I've been programming with c# for 2-ish years. I had a solid understanding of certain types being passed by reference instead of value, but never learned what the Heap or Stack *actually* were. This video finally made it click in my head. I'm glad I wasn't missing out on much and just learned some new names for stuff I already kinda knew :]

  • @kipchickensout
    @kipchickensout 3 ปีที่แล้ว +14

    For anyone watching: You can pass value types by reference, by simply prefixing the type in the parameters with a "ref" keyword. Also look up the "out" keyword

  • @unrealdevop
    @unrealdevop 4 ปีที่แล้ว +10

    This is amazing, great job man. This taught me something very valuable that I was completely unaware of before. Not sure why this wasn't properly explained in the books I read.

  • @gregorio87
    @gregorio87 ปีที่แล้ว

    The best explanation I've seen... I remember being a bit confused about this behavior when first learning JavaScript and this nails it in a very clear way. Great job

  • @DylanWRose
    @DylanWRose 4 ปีที่แล้ว +3

    Preparing for the MTA Software Development Fundamentals exam to meet entry requirements for the WGU Data Analytics degree program. This is something that pops up on the test and has always confused me. The way you've explained it is extremely clear.
    Thank you.

  • @TG47GRG
    @TG47GRG 3 ปีที่แล้ว +3

    this is awesome. You made the concept sound very simple and easy to understand. Thank You!

  • @prasadmadushan
    @prasadmadushan 2 ปีที่แล้ว +1

    Clear explanation with visual Diagram. love it.

  • @dineshkarn3275
    @dineshkarn3275 3 ปีที่แล้ว +1

    Very best explanation with practical example. Thanks a lot . Waiting for your next video

  • @shamikaredkar837
    @shamikaredkar837 3 ปีที่แล้ว +8

    why did i understand this better than what my uni prof taught me? and why am I paying thousands of dollars to the uni only to learn stuff off youtube?

    • @vanyang5381
      @vanyang5381 3 ปีที่แล้ว

      dud I feel exactly the same lol

  • @persiansayed
    @persiansayed ปีที่แล้ว

    Great demonstration and explanation. Thanks 👍

  • @developersfield9018
    @developersfield9018 6 ปีที่แล้ว +2

    nice and easy to understand explanation...

  • @PatilSandip321
    @PatilSandip321 ปีที่แล้ว +1

    Nice one

  • @yess.6558
    @yess.6558 9 หลายเดือนก่อน

    Great video! Thank you!

  • @burreifort
    @burreifort 2 ปีที่แล้ว +7

    4:10 No, you didn't change the value of score2

    • @macoson
      @macoson ปีที่แล้ว +1

      Yes, this got me to laugh as well :D

  • @cicher
    @cicher 4 ปีที่แล้ว +6

    Good explanation, but it is not really about "Heap and Stack", the title should be *"Value and Reference types"*

  • @prakashroyal6386
    @prakashroyal6386 ปีที่แล้ว

    Clear explanation. Thank you for the video!!

  • @muammar88
    @muammar88 2 ปีที่แล้ว +1

    Super! Subscribed! ps. would you kindly group your videos by programming language into seperate PlayLists for convinence? Thanks a million for the great contents!

  • @Tanveer048
    @Tanveer048 2 ปีที่แล้ว

    Thanks for the Sharing of your knowledge

  • @moherna3323
    @moherna3323 3 ปีที่แล้ว

    You're such a great educator

  • @lylewarren4391
    @lylewarren4391 2 หลายเดือนก่อน

    king shit, you are a legend.

  • @محمدحماده-ج8ت6ه
    @محمدحماده-ج8ت6ه 11 หลายเดือนก่อน

    excellent

  • @gabrielyea
    @gabrielyea 5 ปีที่แล้ว

    In c# by default everything passes by value, classes pass their reference as a value. That is my understanding, or I am wrong?

  • @mohokhachai
    @mohokhachai ปีที่แล้ว

    Finally some one

  • @gregorynovikov1450
    @gregorynovikov1450 3 ปีที่แล้ว

    This was interesting, Thank-You

  • @AnasJayyusi
    @AnasJayyusi ปีที่แล้ว

    thank you that was amazing explain

  • @ozanbarsakdogdu8360
    @ozanbarsakdogdu8360 3 ปีที่แล้ว

    in the end of the video you say "int s". Was it "int score"

  • @RageGames_
    @RageGames_ 10 หลายเดือนก่อน

    Nice

  • @BerikAssylbekov
    @BerikAssylbekov 3 ปีที่แล้ว

    It's wrong. Reference type parameters are passed by value. You can test yourself by setting r = null; The pointer on "r" is removed, but "report" is still has pointer.

  • @blackbarry45
    @blackbarry45 4 ปีที่แล้ว +1

    thanks you so much

  • @mohamedshaban5170
    @mohamedshaban5170 ปีที่แล้ว

    Thank you!!

  • @Atezian
    @Atezian 2 ปีที่แล้ว

    Is this useful to someones that doesnt know what the stack and the heap are?

  • @aliabusaleh4039
    @aliabusaleh4039 3 ปีที่แล้ว

    thanks man great job

  • @hhcdghjjgsdrt235
    @hhcdghjjgsdrt235 2 ปีที่แล้ว

    best example

  • @wwg681
    @wwg681 4 ปีที่แล้ว +1

    Can we use struct all the time?

    • @Luizzzzzzzzzzzzzzzzzzzzzzzzzz
      @Luizzzzzzzzzzzzzzzzzzzzzzzzzz 4 ปีที่แล้ว

      Hey have you found the answer to your question?

    • @wwg681
      @wwg681 4 ปีที่แล้ว

      @@Luizzzzzzzzzzzzzzzzzzzzzzzzzz Nope :(

    • @alissonreinaldosilva1119
      @alissonreinaldosilva1119 4 ปีที่แล้ว

      @@wwg681 it's not like Struct is an alternative or replacement for Classes, they have different purposes. Depending on how simple your program is, then yeah you can use only struct, nothing will enforce you to use classes (apart from Program class e.g in a console), but depending on your needs it will just make your task harder for no good reason.

  • @mujmoh7471
    @mujmoh7471 9 หลายเดือนก่อน

    أسطورة

  • @mohokhachai
    @mohokhachai ปีที่แล้ว

    This is it

  • @metteby
    @metteby 5 ปีที่แล้ว +1

    Good explanation. Please lower keyboard noise

  • @Tanveer048
    @Tanveer048 2 ปีที่แล้ว

    This super 👌

  • @at3o
    @at3o 2 ปีที่แล้ว

    💯

  • @WiseWeeabo
    @WiseWeeabo 4 ปีที่แล้ว

    would be useful if you could actually see the text you're writing, how did you mess it up so badly?

  • @Mr.Epsilion
    @Mr.Epsilion 2 ปีที่แล้ว

    Spassibo = true;

  • @BlackSaintNiks
    @BlackSaintNiks ปีที่แล้ว

    Great Learning Video!