C# List of objects 🦸‍♂️

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

КОМЕНТАРІ • 35

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

    using System;
    using System.Collections.Generic;
    namespace MyFirstProgram
    {
    class Program
    {
    static void Main(string[] args)
    {
    List players = new List();
    players.Add(new Player("Chad"));
    players.Add(new Player("Steve"));
    players.Add(new Player("Karen"));
    foreach (Player player in players)
    {
    Console.WriteLine(player);
    }
    Console.ReadKey();
    }
    }
    class Player
    {
    public String username;
    public Player(String username)
    {
    this.username = username;
    }
    public override string ToString()
    {
    return username;
    }
    }
    }

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

      how can i do that inside a method?
      So i want a function to use user input in the console to create a object

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

      @@DiogoGaming2 Just use Convert.ToString() method and create another function in order to take input for instance:
      using System;
      using System.Collections.Generic;
      namespace MyFirstProgram
      {
      class Program
      {
      static void Main(string[] args)
      {
      Player player = new Player("Ali");
      player.ChangeName();
      }
      class Player
      {
      public String name;
      public String new_name;
      public Player(String name)
      {
      this.name = name;
      }
      public void ChangeName()
      {
      Console.WriteLine($"What would you like the new name to be? Current name of player is: {name}");
      String new_name = Convert.ToString(Console.ReadLine());
      name = new_name;
      Console.WriteLine($"Name of player has been changed new name is: {new_name}");
      }
      }
      }
      }

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

      This right here, specifically how to properly write a foreach function, helped me more than you can possibly know!

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

    "Religion, ideology, resources, land, spite, love or just because… No matter how pathetic the reason, it’s enough to start war. War will never cease to exist… reasons can be thought up after the fact… Human nature pursues strife."
    ~ Pain

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

    fast and clear, thank you! I have been trying to find how to make a new object anonymous for so long now

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

    Thanks for the video Bro.

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

    Question:
    I have a list of type "card" called "allCards"
    Each card have a familie and a lvl
    How do I, without hardcoding each list:
    Add a card to a list, that I can call by getting the familie string from the card and then using lvl+1 to look for the next card in said family

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

    Thanks, bro

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

    Very nice.

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

    This is gold, saved me a hell of stress

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

    best

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

    thx man really helping me out here

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

    nice :D

  • @ci-chol
    @ci-chol 2 роки тому +2

    How would you go about sorting or searching this list of objects? Since the anonymous objects are all the same according to the list (duplicate Player objects), how could I sort and perform a binary search to find a user with a specific name?

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

    Can you explain why overriding the ToString method changes the display of the object when passing it through writeline

  •  3 роки тому

    Thanks Bro!

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

    you are such a bro, bro.

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

    Worked!

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

    just some random comment:
    w video !

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

    holy shit I fucking love you

  • @CầnbiếtKo-k5i
    @CầnbiếtKo-k5i Рік тому

    helo , tôi muốn ông làm về khoá học unity được không , nếu không chả lời thì chỉ có người chếết mới làm vậy

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

    where is the video like this but remove and clear instead add pls?

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

    lesson check😇

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

    third

  • @Suckit-b6k
    @Suckit-b6k Рік тому

    christmas

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

    random comment down below

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

    Random Comment

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

    A random comment down below.

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

    Random comment #44

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

    This is not random comment!

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

    random comment

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

    Cloud app in java 😭😭😭