Delegaty - różnica w działaniu

0

Jaka jest róźnica między:

 g.ProcessingCar(new Car.CarMaintranceDepartament(sd.WashCar)); 

a

  g.ProcessingCar(sd.WashCar);

cały kod:

using System;

namespace CarDelegate
{
    public class Application
    {
        public static void Main()
        {
            Garage g = new Garage();
            ServiceDepartament sd = new ServiceDepartament();

           g.ProcessingCar(new Car.CarMaintranceDepartament(sd.WashCar));
         
            g.ProcessingCar(sd.RotateTires);
            g.ProcessingCar(sd.WashCar);

            Console.ReadLine();
        }
        
    }
}


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

namespace CarDelegate
{
    public class ServiceDepartament
    {
        public void WashCar(Car c)
        {
            if (c.isDirty)
                Console.WriteLine("Cleaing a car!");
            else
                Console.WriteLine("This car is already clean!");
        }
        public void RotateTires(Car c)
        {
            if (c.shouldRotate)
                Console.WriteLine("Tires have been rotated!");
            else
                Console.WriteLine("Don't need to be rotated...");
        }
    }
}

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

namespace CarDelegate
{
    public class Garage
    {
        List<Car> carList = new List<Car>();

        public Garage()
        {
            carList.Add(new Car("Paweł", true, false));
            carList.Add(new Car("Katarzyna", false, false));
            carList.Add(new Car("Roman", true, true));
            carList.Add(new Car("Lukasz", false, true));
            carList.Add(new Car("Paweł", true, true));
            carList.Add(new Car("Paweł", false, false));

        }

        public void ProcessingCar(Car.CarMaintranceDepartament proc)
        {
            foreach (Car c in carList)
                proc(c);
        }
    }
}


using System;
using System.Collections.Generic;

namespace CarDelegate
{
    public class Car
    {
        // 
        public string name { set; get; }
        public bool isDirty { set; get; }
        public bool shouldRotate { set; get; }

        public delegate void CarMaintranceDepartament(Car car);

        // 
        public Car(string petName, bool washCar, bool rotateTires)
        {
            name = petName;
            isDirty = washCar;
            shouldRotate = rotateTires;
        }
    }
}
 
1

Nie ma.

1

Drugie jest krotsze.

1 użytkowników online, w tym zalogowanych: 0, gości: 1