Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active May 17, 2023 07:42
Show Gist options
  • Save Strelok78/098ea423858f35f387d12ef26bc8cbf9 to your computer and use it in GitHub Desktop.
Save Strelok78/098ea423858f35f387d12ef26bc8cbf9 to your computer and use it in GitHub Desktop.
Player class, with fields containing information about the player and a method that displays the information on the screen.
internal class Program
{
public static void Main()
{
Console.WriteLine("Enter Players' name");
string name = Console.ReadLine();
Console.WriteLine("Enter Players' age");
int age = int.Parse(Console.ReadLine());
Player player = new Player(age, name);
player.ShowDetails();
}
}
class Player
{
private int _age;
private string _name;
public Player(int age, string name)
{
_age = age;
_name = name;
}
public void ShowDetails()
{
Console.WriteLine($"Players name: {_name}\nPlayers age: {_age}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment