Skip to content

Instantly share code, notes, and snippets.

@Lycheejam
Last active November 29, 2017 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lycheejam/8a2c805a565b11b1f3848cd01f71f71b to your computer and use it in GitHub Desktop.
Save Lycheejam/8a2c805a565b11b1f3848cd01f71f71b to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace inheritance
{
class Program
{
static void Main(string[] args)
{
//インスタンス生成
Pc pc = new Pc("AKRACING1","1800*900","core i7-6700k", "GTX 1070", 3500, 650);
Console.WriteLine("PCクラス");
Console.WriteLine("CPU:{0}", pc.Cpu);
Console.WriteLine("GPU:{0}", pc.Gpu);
Console.WriteLine("HDD:{0}GB", pc.Hdd);
Console.WriteLine("電源:{0}W", pc.Psu);
Console.WriteLine("イス:{0}", pc.Chair);
Console.WriteLine("デスク:{0}", pc.Desk);
GameEnvironment ge1 = pc;
if (ge1.Equals(pc))
{
Console.WriteLine("PCはゲーム環境");
}
Device dvc = new Device("AKRACING2", "1800*900",
"Rival 300", "BenQ XL2411", "FILCO Majestouch 2");
Console.WriteLine("周辺機器クラス");
Console.WriteLine("イス:{0}", dvc.Chair);
Console.WriteLine("デスク:{0}", dvc.Desk);
Console.WriteLine("マウス:{0}", dvc.Mouse);
Console.WriteLine("モニター:{0}", dvc.Monitor);
Console.WriteLine("キーボード:{0}", dvc.Keyboard);
GameEnvironment ge2 = dvc;
if (ge2.Equals(dvc))
{
Console.WriteLine("周辺機器はゲーム環境");
}
}
}
/// <summary>
/// ゲーム環境クラス
/// </summary>
public class GameEnvironment
{
public string Chair { get; set; }
public string Desk { get; set; }
}
/// <summary>
/// ゲーム環境クラスを継承したPc(パソコン)クラス
/// </summary>
public class Pc : GameEnvironment
{
public string Cpu { get; set; }
public string Gpu { get; set; }
public int Hdd { get; set; }
public int Psu { get; set; }
//コンストラクタ
public Pc(string chair, string desk,string cpu,string gpu,int hdd,int psu)
{
this.Chair = chair;
this.Desk = desk;
this.Cpu = cpu;
this.Gpu = gpu;
this.Hdd = hdd;
this.Psu = psu;
}
}
/// <summary>
/// ゲーム環境クラスを継承したDevice(周辺機器)クラス
/// </summary>
public class Device : GameEnvironment
{
public string Mouse { get; set; }
public string Monitor { get; set; }
public string Keyboard { get; set; }
//コンストラクタ
public Device(string chair, string desk, string mouse, string monitor, string keyboard)
{
this.Chair = chair;
this.Desk = desk;
this.Mouse = mouse;
this.Monitor = monitor;
this.Keyboard = keyboard;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment