Пример #1
0
    static void Main()
    {
        Cello pluma1 = new Cello("rojo");

        (pluma1 as IPluma).Escribir("Hola Mundo");
        pluma1.Abrir();
        (pluma1 as IPluma).Escribir("Hola Mundo");
    }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Ejemplo del uso de interfaces \n");
            IPluma miCello  = new Cello("Azul");
            IPluma miParker = new Parker("Negro");

            miCello.Abrir();
            miCello.Color = "Azul";
            miCello.Escribir($"Escribiendo este mensaje con la pluma marca Cello en color {miCello.Color} \n");
            miCello.Cerrar();

            miParker.Abrir();
            miParker.Color = "Negro";
            miParker.Escribir($"Parker escribe mejor los mensaje por ahora en color {miParker.Color} \n");
            miParker.Cerrar();
        }
        private void BtnInterface_Click(object sender, RoutedEventArgs e)
        {
            //2019103018
            IPen pen1 = new Cello();

            IPen pen2 = new Parker();

            pen1.Open();
            pen2.Open();

            IPen pen3 = new Parker2();
            //pen3.GetBrandName()//this gives error


            Parker2 pen4 = new Parker2();

            pen4.GetBrandName();//this works
        }
Пример #4
0
    public static void Main()
    {
        Parker p  = new Parker();
        IPen   p2 = new Parker();

        /*List<IPen> plumas=new List<IPen>();
         * plumas.Add(p as IPen);
         * plumas.Add(p2);
         * foreach(IPen pluma in plumas)
         *      (pluma as IPen).Write("Hola");*/

        IPen pen1 = new Cello();

        pen1.Open();
        pen1.Write("This is my Cello pen.");
        pen1.Close();

        IPen pen2 = new Parker();

        pen2.Open();
        pen2.Write("This is my Parker pen.");
        pen2.Close();
    }