Advertisement
ZhongNi

Working with classes

Mar 18th, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Classes
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Player[] players = {
  10.             new Player( "YuanZhi","BengHuaiXingQiongTieDao"),
  11.             new Player("ZhongNi","WoT")
  12.             };
  13.  
  14.             for (int i = 0; i < players.Length; i++)
  15.             {
  16.                 players[i].ShowInfo();
  17.                 Console.WriteLine();
  18.             }
  19.         }
  20.     }
  21.  
  22.     class Player
  23.     {
  24.         private string _name;
  25.         private string _game;
  26.  
  27.         public Player(string name, string game)
  28.         {
  29.             _name = name;
  30.             _game = game;
  31.         }
  32.  
  33.         public void ShowInfo()
  34.         {
  35.             Console.Write($"Player: {_name}\nGame: {_game}\n");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement