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
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
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.
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
Thanks, bro
Very nice.
This is gold, saved me a hell of stress
best
thx man really helping me out here
nice :D
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
Can you explain why overriding the ToString method changes the display of the object when passing it through writeline
Thanks Bro!
you are such a bro, bro.
Worked!
just some random comment:
w video !
holy shit I fucking love you
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
where is the video like this but remove and clear instead add pls?
lesson check😇
third
christmas
random comment down below
Random Comment
A random comment down below.
Random comment #44
This is not random comment!
random comment
Cloud app in java 😭😭😭