Advertisement
SPavelA

OOPTask1ClassPlayer

Oct 22nd, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | Gaming | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace OOPTask1ClassPlayer
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<Player> players = new List<Player>();
  11.  
  12.             players.Add(new Player("Вася", "задрот", 27));
  13.             players.Add(new Player("Петя", "читер", 14));
  14.             players.Add(new Player("Гена", "ламер", 17));
  15.  
  16.             foreach (Player player in players)
  17.             {
  18.                 player.ShowInfo();
  19.             }
  20.         }
  21.     }
  22.  
  23.     class Player
  24.     {
  25.         private string _name;
  26.         private string _description;
  27.         private int _age;
  28.  
  29.         public Player(string name, string description, int age)
  30.         {
  31.             _name = name;
  32.             _description = description;
  33.             _age = age;
  34.         }
  35.  
  36.         public void ShowInfo()
  37.         {
  38.             Console.WriteLine($"Игроку {_name} {_age} лет и он {_description}.");
  39.         }
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement