C# Lists 📃

Поділитися
Вставка
  • Опубліковано 26 січ 2025

КОМЕНТАРІ • 107

  • @BroCodez
    @BroCodez  3 роки тому +44

    using System;
    using System.Collections.Generic;
    namespace MyFirstProgram
    {
    class Program
    {
    static void Main(string[] args)
    {
    // List = data structure that represents a list of objects that can be accessed by index.
    // Similar to array, but can dynamically increase/decrease in size
    // using System.Collections.Generic;
    List food = new List();
    food.Add("pizza");
    food.Add("hamburger");
    food.Add("hotdog");
    food.Add("fries");
    //Console.WriteLine(food[0]);
    //Console.WriteLine(food[1]);
    //Console.WriteLine(food[2]);
    //Console.WriteLine(food[3]);
    //food.Remove("fries");
    //food.Insert(0, "sushi");
    //Console.WriteLine(food.Count);
    //Console.WriteLine(food.IndexOf("pizza"));
    //Console.WriteLine(food.LastIndexOf("fries"));
    //Console.WriteLine(food.Contains("pizza"));
    //food.Sort();
    //food.Reverse();
    //food.Clear();
    //String[] foodArray = food.ToArray();
    foreach (String item in food)
    {
    Console.WriteLine(item);
    }
    Console.ReadKey();
    }
    }
    }

    • @vamshidharreddy3739
      @vamshidharreddy3739 3 роки тому +2

      Never stop making vids bro plzzz keep going ❤️❤️❤️

    • @chrissauter7324
      @chrissauter7324 2 роки тому

      I am having some difficulty with being able to manually entering the items into my list through a loop. The problem is specifically the formatting of the 2 foreach loops (same problem with both, and problems with my new List equation
      foreach(String firearms in MyCollection[])
      {
      Console.WriteLine(firearms);
      }
      (for this I am getting CS0443 -Syntax error, value expected/CS0030 - Cannot convert type 'char' to 'string' and CS0136 - A local or parameter named 'firearms cannot be declared in this scope because that name is used in enclosing local scope to define a local or parameter
      also have a problem with this statement -
      firearms = Console.ReadLine().ToString(MyCollection[]);
      Console.WriteLine(MyCollection[]);

    • @richardrackley2430
      @richardrackley2430 Рік тому +1

      @@chrissauter7324 I know this is late but to address your issues:
      Just remove square brackets "[]" from all your code. You will only use this when references a numerical index for your list, similar to an array.

  • @maxwong1768
    @maxwong1768 2 роки тому +37

    Summarize :
    List is an advanced version of array with many useful methods but it consumes more memory than array .
    Method of list
    Declare a list

    List strList = new List();
    // style 1

    List strList = new();
    // style 2 (quicker)

    Add/Insert/Remove an element

    Add an element

    strList.Add("a");

    Insert an element

    strList.Insert(1, "b");
    // 1 = index

    Remove an element

    strList.Remove("a");

    Size of a list

    strList.Count()

    Index of a specific element

    First index

    strList.IndexOf("a");

    Last index

    strList.LastIndexOf("a");

    Check whether a list contains a specific element

    strList.Contains("a");

    Sort the list

    Sort the list alphabetically

    strList.Sort();

    Sort the list anti-alphabetically

    strList.Reverse();

    Clear the list

    strList.Clear();

    Switch between array and list

    Convert from array to list

    List strList = strArray.ToList();
    // style 1

    List strList = new();
    strList.AddRange(strArray);
    // style 2

    Convert from list to array

    String[] strArray = strList.ToArray();
    If you want to print list for testing .
    static void Print(List strList)
    {
    foreach (String str in strList)
    {
    Console.Write(str);
    }
    Console.WriteLine();
    }
    static void Print(List intList) // method overloading
    {
    foreach (int i in intList)
    {
    Console.Write(i);
    }
    Console.WriteLine();
    }

    • @legelf
      @legelf Рік тому +2

      thanks man, i wish i had found this comment before because I just wanted to refresh my memory on lists and the video was kinda slow, this would've been sm faster 😂😂

    • @precious12
      @precious12 9 місяців тому +1

      🥳

    • @Wall_Man_Studio_WMS
      @Wall_Man_Studio_WMS 6 місяців тому +1

      👍

    • @floramsi
      @floramsi 2 дні тому

      tysm !!!

  • @ShiftTGC
    @ShiftTGC 2 роки тому +32

    I'm 90% sure I tried in the past to learn and understand Arrays and failed hard, even with friends trying to explain, and even tho this is a tutorial for lists, thank you for teaching me what I wanted to do with Arrays in less than a minute xD

  • @RickVegasGames
    @RickVegasGames Рік тому +2

    I literally never knew the difference between list and array until the 0:18 second of this. Thank you!

  • @Mr-Eloda
    @Mr-Eloda 2 роки тому +8

    Man you sure know how to make a good, quick and easy to understand video.

  • @FHULUFHELONORMANMAMUSHIA-ng1up

    ONE OF THE BEST TEACHERS OF COMPLEX THINGS 🤔🙌

  • @samdeur
    @samdeur 3 роки тому +9

    Thank you bin looking at C# lists vid but yours is the first that is clear enough to me.. really helpful thanks..

  • @sammaciel7835
    @sammaciel7835 Рік тому +3

    Amazing tutorial. You have NO IDEA how much you helped me just now. Thanks so much!!! I have Lists sorted in my brain from now on. :)

  • @gingr4002
    @gingr4002 Рік тому

    The best explanation and thankfully for VDO.

  • @pydzio
    @pydzio 2 роки тому +1

    Best explanation so far on UA-cam.

  • @cride9858
    @cride9858 3 роки тому +2

    best coding tutorial youtuber ngl

  • @akairibbon4658
    @akairibbon4658 8 місяців тому +1

    amazing video, great teaching man

  • @nyeinchannyinyi19
    @nyeinchannyinyi19 3 роки тому +2

    Nice tutorial
    Thanks

  • @lavish1673
    @lavish1673 Рік тому

    This cleared everything about lists , Thanks

  • @lesegoseko5920
    @lesegoseko5920 8 місяців тому

    you are the best 🔥🔥🔥🔥🔥

  • @marrlowne5884
    @marrlowne5884 2 роки тому +1

    Thanks! Everything very good explained

  • @gamingclipsrsa
    @gamingclipsrsa 4 місяці тому

    Im writing an exam in 2 hours and i understand lists better than the 2 months in class. Thank you

  • @abdulsametaybaz3321
    @abdulsametaybaz3321 2 роки тому

    good explanation

  • @abdelmawgood9282
    @abdelmawgood9282 Рік тому

    Descriptive ,simple , concentrate and short video

  • @syedmubazir4371
    @syedmubazir4371 2 роки тому +1

    Watched your video and instantly subscribed! A great Content ❤️💯⭐

  • @FunnySubmarine-ij4zk
    @FunnySubmarine-ij4zk 11 місяців тому

    Thank you. These short refresher videos are good.

  • @bateriadelitio12v
    @bateriadelitio12v 2 роки тому

    awesome, brooooooo!!!! thanks a lot

  • @syafiqbasri_
    @syafiqbasri_ 2 роки тому

    W channel. Tq very much sir!

  • @joshnjoshgaming
    @joshnjoshgaming 3 роки тому +2

    very helpful and easy to understand :D

  • @seckopi23
    @seckopi23 Рік тому

    thanks for making this tutorial

  • @Eh-man
    @Eh-man 9 місяців тому

    Dude you're a life saver im not joking.

  • @spartanranger
    @spartanranger 3 роки тому +1

    Thanks for the video Bro.

  • @MasterIsroilov-o9q
    @MasterIsroilov-o9q 7 місяців тому

    Nice clases Bro!

  • @jonlbs7
    @jonlbs7 Рік тому

    Very awesome .. thank you!!

  • @springbertstudios7005
    @springbertstudios7005 10 місяців тому

    Thanks this is going to help me a lot

  • @FedoraChan
    @FedoraChan Рік тому

    You're the goat Mr Bro !

  • @amjadhani8929
    @amjadhani8929 Рік тому

    Best channel ever

  • @yeetswa
    @yeetswa 2 роки тому +1

    very clear and helpful thankyou

  • @warrenaustin4083
    @warrenaustin4083 Рік тому

    This video helped me so much, thanks

  • @moorurr
    @moorurr Рік тому

    youre so good at explaining things oh my god

  • @ab_obada5012
    @ab_obada5012 Рік тому

    Thanks to your efforts :D

  • @abdulpianist9731
    @abdulpianist9731 Рік тому

    your type speed is insane

  • @MoHaTa-u3f
    @MoHaTa-u3f 3 місяці тому

    Lemme make sure I understand this right:
    Difference between arrays and lists illustrated with a game example:
    Say you are making a game with a food and inventory system. The game has a fixed amount of food items/recipes, so they are hardcoded into the array before running the game. This means that the player cannot make "new" food that isnt in the game. If you want to add more recipes into the game later in a new update, you need to update the array.
    Likewise, a player might have an inventory where they can store their food, whether they made it or crafted it. The inventory has a "list" of items inside of it that can increase or decrease by gathering/cooking new food, or by eating. This means that the player can influence the size of the list in-game, so the list is dynamic.
    Is this correct? Say you collect an item in a game, after collecting it you can call a "collect();" method (which say you already made) that performs a "food.Add();" command

  • @eeronat
    @eeronat Рік тому

    On behalf of Lists everywhere, I take exception, sir, to your characterization of Lists as "wasting" more memory. It is true that Lists use more memory than arrays; but we'll have you know that those memory resources are very well spent!

  • @mihaelh6783
    @mihaelh6783 2 роки тому

    Whenever there's a list of objects the objects always gotta be a food of sorts :) great video man.

  • @FullExtension1
    @FullExtension1 2 роки тому

    you are such a bro, bro.

  • @olutayodurodola5891
    @olutayodurodola5891 Рік тому

    thanks for going straight to the point, nice tutorial

  • @andrecoccoconde3668
    @andrecoccoconde3668 3 роки тому

    Another great video my man.

  • @raunakbasnet7955
    @raunakbasnet7955 2 роки тому

    I was trying to move from js to C# ,array in C# was feeling so uncomfortable for me. This video made me clear how do i create array as js in C#.

  • @EbKingSolomon
    @EbKingSolomon Рік тому

    Love it!!!! Thanks for everything

  • @simontillema5599
    @simontillema5599 2 роки тому +1

    Perfect! Thank you!

  • @xxdangerxx1244
    @xxdangerxx1244 2 роки тому

    yeah brou, your the best, gigachad

  • @hungdangviet8986
    @hungdangviet8986 2 роки тому +1

    short and informative. I really love this.

  • @Rishabh-p5e
    @Rishabh-p5e Рік тому

    👍👍

  • @huseyncfrov2514
    @huseyncfrov2514 Рік тому +1

    "Those who stand at the top determine what's wrong and what's right! This very place is neutral ground! Justice will prevail, you say? But of course it will! Whoever wins this war becomes justice!"
    ~ Don Quixote Doflamingo

  • @thecutepro2447
    @thecutepro2447 3 роки тому

    the best of the best!!

  • @jacobomisaelcanul6747
    @jacobomisaelcanul6747 3 роки тому

    Very well explained

  • @mateusw.
    @mateusw. 2 роки тому

    Thank you. Helped me!

  • @viniciuslima1064
    @viniciuslima1064 2 місяці тому

    Thanks bro

  •  3 роки тому +1

    Thanks Bro!

  • @Blane35
    @Blane35 11 місяців тому

    How do I get the average value? I want to use the
    Variable.Average(); Command and then assign this average to another variable to display.

  • @LuzuVlogsGamer
    @LuzuVlogsGamer Рік тому

    can we add custom Lists like arrays with for loop like List.Add([ i ])=Console.ReadLine();
    Can we do something like that for Lists? or are they only added manually for Website application

  • @heymide
    @heymide Рік тому

    This list method can be used to make a todo list, right?

  • @zvonkocosic5939
    @zvonkocosic5939 2 роки тому

    How do you change number 3 to 0 in list?
    example:
    list numbers = new list {1,2,3,4,5,6,7,8,9};
    Number 3 needs to be number 0.
    Is there any way to do some list.Replace() method or anything?
    Thank you.

    • @urano3604
      @urano3604 2 роки тому

      What if you use a
      "
      numbers.remove(3);
      numbers.insert(2, 0);
      "
      ?

    • @TacoLocous
      @TacoLocous Рік тому

      numbers[2] = 0;

  • @Wall_Man_Studio_WMS
    @Wall_Man_Studio_WMS 6 місяців тому

    Thanks

  • @superkingpunga
    @superkingpunga 6 місяців тому

    Shot bro.

  • @tanoryjakaperdana1419
    @tanoryjakaperdana1419 2 роки тому

    05:43 what is reverse for?

    • @easternunit2009
      @easternunit2009 2 роки тому

      It’s sorts it alphabetically, but in reverse.

  • @Kingiman
    @Kingiman 2 роки тому

    so you could use this to create an inventory system for a video game basically ?

    • @Ayman73795
      @Ayman73795 Рік тому

      hello same name person just spelled differently.

  • @jillieduke
    @jillieduke 2 роки тому

    OMG thank you ! :)

  • @IndustrialBonecraft
    @IndustrialBonecraft 3 роки тому

    Is there any benefit to this over doing something like:
    string[] food = new string[] { "pizza", "hamburger", "hotdog", "fries"};
    and then using '(0, food.Length);', which seems to circumvent the need to declare a definite array size?

    • @venatusgullebulle3389
      @venatusgullebulle3389 3 роки тому +5

      I don't quiete have an answer for you but my teacher which owns his own tech company says that you almost never use arrays since lists are much friendlier for continuous development. The only time to use arrays is for things which are actually 100% certain, like there are only 12 months in a year, you don't need a list for that.

  • @hellakuabb8166
    @hellakuabb8166 Рік тому

    what about dynamic arrays?

  • @alexmelamud9750
    @alexmelamud9750 2 роки тому

    Thanks man

  • @queendreem-gk4is
    @queendreem-gk4is Рік тому

    thancks

  • @gaminggoddessaria
    @gaminggoddessaria 2 роки тому

    yeah but how do you get one of the elements out of the list??

    • @simontillema5599
      @simontillema5599 2 роки тому +1

      Same way as with an array: "string x = food[0];" for the first item in the list.

    • @HandlesAreStupid11
      @HandlesAreStupid11 2 роки тому +1

      @@simontillema5599 I appreciate that a lot, this gave me what I needed to finish a project up. All I needed was to pull random objects from a list.

  • @EDW4RD249
    @EDW4RD249 2 роки тому

    What if I need to udate the value in index 0?

  • @simplyjemelah8276
    @simplyjemelah8276 3 роки тому

    how to make multiple list?

  • @augischadiegils.5109
    @augischadiegils.5109 3 роки тому

  • @whitedinamo
    @whitedinamo 3 роки тому

    lesson check😇

  • @mohamedabouzeid2936
    @mohamedabouzeid2936 2 роки тому

    list is so similar to vector in C++

  • @triton5457
    @triton5457 2 роки тому

    pizza 🍕 😀

  • @zandemon
    @zandemon 9 місяців тому

    Super random comment 9999

  • @exeplayz4695
    @exeplayz4695 Місяць тому

    now i feel hungry

  • @akshaysathyanath7755
    @akshaysathyanath7755 2 роки тому

    import random
    print(random.randint(1,four twenty sixty nine))

  • @Proviper666
    @Proviper666 2 роки тому

    Hi

  • @the_dude_josh
    @the_dude_josh Рік тому

    A random comment down below.

  • @borodasichevich7653
    @borodasichevich7653 2 місяці тому

    random comment below

  • @abiralpoudel3889
    @abiralpoudel3889 25 днів тому

    random comment

  • @IsRaphaelGo
    @IsRaphaelGo 4 місяці тому

    guh

  • @ysawer
    @ysawer 10 місяців тому

    this is a random commment AHHHHHHHHHHHH aHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @tbtmtfth
    @tbtmtfth Рік тому

    adsdadadassa