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 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}"); } } } }
"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
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?
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;
}
}
}
how can i do that inside a method?
So i want a function to use user input in the console to create a object
@@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}");
}
}
}
}
This right here, specifically how to properly write a foreach function, helped me more than you can possibly know!
"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
fast and clear, thank you! I have been trying to find how to make a new object anonymous for so long now
Thanks for the video Bro.
Thanks, bro
best
Very nice.
This is gold, saved me a hell of stress
Can you explain why overriding the ToString method changes the display of the object when passing it through writeline
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?
LINQ
you are such a bro, bro.
thx man really helping me out here
nice :D
just some random comment:
w video !
Thanks Bro!
holy shit I fucking love you
where is the video like this but remove and clear instead add pls?
Worked!
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
lesson check😇
random comment down below
third
christmas
Random Comment
A random comment down below.
This is not random comment!
random comment
Random comment #44
Cloud app in java 😭😭😭