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
Жыл бұрын
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
11 ай бұрын
@@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
3 ай бұрын
This right here, specifically how to properly write a foreach function, helped me more than you can possibly know!
@teamcheese1045
2 жыл бұрын
fast and clear, thank you! I have been trying to find how to make a new object anonymous for so long now
@octaviolozada8697
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?
@ballisticmind
Жыл бұрын
This is gold, saved me a hell of stress
@spartanranger
2 жыл бұрын
Thanks for the video Bro.
@tdkom
2 жыл бұрын
thx man really helping me out here
2 жыл бұрын
Thanks Bro!
@Warpgatez
Жыл бұрын
Very nice.
@TheCodeHunter
2 жыл бұрын
nice :D
@__foo__
Жыл бұрын
Worked!
@richardtaveras7028
5 ай бұрын
Can you explain why overriding the ToString method changes the display of the object when passing it through writeline
@FullExtension1
Жыл бұрын
you are such a bro, bro.
@syawo7062
Жыл бұрын
holy shit I fucking love you
@huseyncfrov2514
6 ай бұрын
"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
@user-wz9fo1eg1q
9 ай бұрын
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
@whitedinamo
2 жыл бұрын
lesson check😇
@aditya_asundi
2 жыл бұрын
third
@SweetPeachannel
Жыл бұрын
where is the video like this but remove and clear instead add pls?
Пікірлер: 30