C# Lists πŸ“ƒ



C# lists tutorial example explained #C# #list #tutorial // List = data structure that represents a list of objects that can be accessed …

30 Comments

  1. 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<String> food = new List<String>();

    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();

    }

    }

    }

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

  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?

Leave a Reply

© 2023 53GB