C# Lists 📃

Поділитися
Вставка
  • Опубліковано 2 лип 2021
  • C# lists tutorial example explained
    #C# #list #tutorial
    // 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;
  • Наука та технологія

КОМЕНТАРІ • 97

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

    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 Рік тому

      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 Рік тому

      @@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.

  • @ShiftTGC
    @ShiftTGC Рік тому +24

    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

  • @maxwong1768
    @maxwong1768 Рік тому +33

    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 7 місяців тому +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 3 місяці тому +1

      🥳

    • @Wall_Man_Studio_WMS
      @Wall_Man_Studio_WMS 23 дні тому +1

      👍

  • @Mr-Eloda
    @Mr-Eloda Рік тому +7

    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 2 роки тому +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 9 місяців тому +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. :)

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

    Best explanation so far on UA-cam.

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

    Finally understand how to use Lists. Thank you!

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

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

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

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

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

    best coding tutorial youtuber ngl

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

    Perfect! Thank you!

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

    Dude you're a life saver im not joking.

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

    Another great video my man.

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

    thanks for going straight to the point, nice tutorial

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

    amazing video, great teaching man

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

    Thanks! Everything very good explained

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

    very helpful and easy to understand :D

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

    Love it!!!! Thanks for everything

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

    The best explanation and thankfully for VDO.

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

    Thank you. These short refresher videos are good.

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

    you are the best 🔥🔥🔥🔥🔥

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

    This cleared everything about lists , Thanks

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

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

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

    Thanks for the video Bro.

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

    Thanks this is going to help me a lot

  • @jonlbs7
    @jonlbs7 7 місяців тому

    Very awesome .. thank you!!

  • @mateusw.
    @mateusw. Рік тому

    Thank you. Helped me!

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

    You're the goat Mr Bro !

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

    youre so good at explaining things oh my god

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

    very clear and helpful thankyou

  • @user-ic5er5wc4s
    @user-ic5er5wc4s Місяць тому

    Nice clases Bro!

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

    Nice tutorial
    Thanks

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

    Thanks Bro!

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

    the best of the best!!

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

    awesome, brooooooo!!!! thanks a lot

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

    Thanks to your efforts :D

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

    W channel. Tq very much sir!

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

    OMG thank you ! :)

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

    Very well explained

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

    Best channel ever

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

    thanks for making this tutorial

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

    yeah brou, your the best, gigachad

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

    Descriptive ,simple , concentrate and short video

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

    This video helped me so much, thanks

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

    you are such a bro, bro.

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

    good explanation

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

    Thanks man

  • @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!

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

    short and informative. I really love this.

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

    your type speed is insane

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

    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#.

  • @user-id1hl2vi3c
    @user-id1hl2vi3c 6 місяців тому

    👍👍

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

  • @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

  • @Wall_Man_Studio_WMS
    @Wall_Man_Studio_WMS 23 дні тому

    Thanks

  • @superkingpunga
    @superkingpunga 17 днів тому

    Shot bro.

  • @huseyncfrov2514
    @huseyncfrov2514 7 місяців тому

    "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

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

    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 2 роки тому +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.

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

    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 Рік тому

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

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

      numbers[2] = 0;

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

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

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

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

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

      hello same name person just spelled differently.

  • @queendreem-gk4is
    @queendreem-gk4is 6 місяців тому

    thancks

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

    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.

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

    how to make multiple list?

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

    lesson check😇

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

    list is so similar to vector in C++

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

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

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

    what about dynamic arrays?

  • @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.

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

    05:43 what is reverse for?

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

      It’s sorts it alphabetically, but in reverse.

  • @zandemon
    @zandemon 3 місяці тому

    Super random comment 9999

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

    pizza 🍕 😀

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

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

  • @the_dude_josh
    @the_dude_josh 7 місяців тому

    A random comment down below.

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

    Hi

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

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

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

    adsdadadassa