using System;
using System.Collections.Generic;
using System.Text;

namespace Generika
{
    public class Pair<T>
    {
        private T partA;
        private T partB;

        public Pair(T a, T b)
        {
            partA = a;
            partB = b;
        }

        public T PartA
        {
            get { return partA; }
        }

        public T PartB
        {
            get { return partB; }
        }

        public T GetCounterpart(T member)
        {
            if (member.Equals(partA))
                return partB;
            else if (member.Equals(partB))
                return partA;
            else
            {
                throw new ArgumentException("Argument ist in Paar nicht vorhanden!");
            }
        }
    }


    class FilmCharacter
    {
        string name;
        public FilmCharacter(string s)
        {
            name = s;
        }

        public override string ToString()
        {
            return name;
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            // Verwahrung und Abfrage von int-Werten
            Pair<int> pair = new Pair<int>(12, 5);
            int n = pair.GetCounterpart(12);
            Console.WriteLine(" Gegenstück zu 12:  {0}", n);

            // Verwahrung und Abfrage von FilmCharacter-Objekten
            FilmCharacter holmes = new FilmCharacter("Sherlock Holmes");
            FilmCharacter watson = new FilmCharacter("Dr. Watson");

            Pair<FilmCharacter> famousPair = new Pair<FilmCharacter>(holmes, watson);
            FilmCharacter cp = famousPair.GetCounterpart(holmes);
            Console.WriteLine(" Gegenstück zu Holmes:  {0}", cp);
        }
    }
}
