ColoredItem<Sword> blueSword = new ColoredItem<Sword>(new Sword(), ConsoleColor.Blue);
ColoredItem<Bow> redBow = new ColoredItem<Bow>(new Bow(), ConsoleColor.Red);
ColoredItem<Axe> yellowAxe = new ColoredItem<Axe>(new Axe(), ConsoleColor.Green);
blueSword.Display();
redBow.Display();
yellowAxe.Display();
Console.ReadLine();
public class ColoredItem<T>
{
private T item;
private ConsoleColor color;
public ColoredItem(T item, ConsoleColor color)
{
this.item = item;
this.color = color;
}
public void Display()
{
ConsoleColor prevBGColor = Console.BackgroundColor;
Console.BackgroundColor = color;
Console.WriteLine(item);
Console.BackgroundColor = prevBGColor;
}
}
public class Sword { }
public class Bow { }
public class Axe { }
ColoredItem<Sword> blueSword = new ColoredItem<Sword>(new Sword(), ConsoleColor.Blue);
ColoredItem<Bow> redBow = new ColoredItem<Bow>(new Bow(), ConsoleColor.Red);
ColoredItem<Axe> yellowAxe = new ColoredItem<Axe>(new Axe(), ConsoleColor.Green);
blueSword.Display();
redBow.Display();
yellowAxe.Display();
Console.ReadLine();
public class ColoredItem<T>
{
private T item;
private ConsoleColor color;
public ColoredItem(T item, ConsoleColor color)
{
this.item = item;
this.color = color;
}
public void Display()
{
ConsoleColor prevBGColor = Console.BackgroundColor;
Console.BackgroundColor = color;
Console.WriteLine(item);
Console.BackgroundColor = prevBGColor;
}
}
public class Sword { }
public class Bow { }
public class Axe { }