Beispiel #1
0
        private void EnumCasting_Inspector()
        {
            Debug.LogWarning("Begin of Enum Casting" + Environment.NewLine);

            //	Explicitly cast from Vehicle's underlying Type (int)
            Vehicle vehicle = (Vehicle)2;

            //	Prints "Compact"
            Debug.Log("Vehicle #2: " + vehicle.ToString() + Environment.NewLine);

            //	Explicitly cast to Vehicle's underlying Type (int)
            int vehicleInt = (int)Vehicle.Hatchback;

            //	Prints "1"
            Debug.Log("Vehicle.Hatchback's value: " + vehicleInt.ToString() + Environment.NewLine);


            //	Implicit cast to "None".  Implicit cast works for 0 only
            Vehicles vehiclesNone = 0;

            //	Prints "0"
            Debug.Log("vehiclesNone: " + vehiclesNone.ToString() + Environment.NewLine);

            //	Explicitly cast ~0, which means the "bitwise opposite of zero" or "all", to Vehicles
            Vehicles vehiclesAll = (Vehicles) ~0;

            //	Prints "-1", which is the enum version of "all" (due to bitwise math)
            Debug.Log("vehiclesAll: " + vehiclesAll.ToString() + Environment.NewLine);

            //	Prints true for each line, since everything is contained in vehiclesAll
            foreach (Vehicles veh in EnumUtility.GetList <Vehicles>())
            {
                Debug.Log("vehiclesAll contains " + veh.ToString() + "? " + vehiclesAll.Contains(veh) + Environment.NewLine);
            }
        }
Beispiel #2
0
 public void Drive(Vehicle vehicle)
 {
     if (Vehicles.Contains(vehicle))
     {
         this.Vehicle = vehicle;
         Console.WriteLine($"{Name} conduce: {vehicle.VehicleInUse}");
     }
 }