public void OnMousePress(MouseButton button) { if (button == MouseButton.Left) { Giraffe.Quit(); } }
// EXPLICIT CONVERSIONS (CASTS): Explicit conversions require a cast expression. // Casting is required when information might be lost in the conversion, or when the conversion might not succeed for other reasons. // Typical examples include numeric conversion to a type that has less precision or a smaller range, // and conversion of a base-class instance to a derived class. private static void Example3() { double x = 1234.7; int a; // Cast double to int. a = (int)x; Console.WriteLine(a); // Output: 1234 // For reference types, an explicit cast is required if you need to convert from a base type to a derived type: // Create a new derived type. Giraffe giraffe = new Giraffe(); // Implicit conversion to base type is safe. Animal animal = giraffe; // Explicit conversion is required to cast back // to derived type. Note: This will compile but will // throw an exception at run time if the right-side // object is not in fact a Giraffe. Giraffe g2 = (Giraffe)animal; // In some reference type conversions, the compiler cannot determine whether a cast will be valid. // It is possible for a cast operation that compiles correctly to fail at run time. Reptile snake = (Reptile)animal; // C# provides the is operator to enable you to test for compatibility before actually performing a cast. if (animal is Giraffe) { return; } }
static void Main() { SafeCasting app = new SafeCasting(); // Use the is operator to verify the type. // before performing a cast. Giraffe g = new Giraffe(); app.UseIsOperator(g); // Use the as operator and test for null // before referencing the variable. app.UseAsOperator(g); // Use the as operator to test // an incompatible type. SuperNova sn = new SuperNova(); app.UseAsOperator(sn); // Use the as operator with a value type. // Note the implicit conversion to int? in // the method body. int i = 5; app.UseAsWithNullable(i); double d = 9.78654; app.UseAsWithNullable(d); // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); }
static void Main(string[] args) { // Use the is operator to verify the type. // before performing a cast. Giraffe g = new Giraffe(); UseIsOperator(g); // Use the as operator and test for null // before referencing the variable. UseAsOperator(g); // Use the as operator to test // an incompatible type. SuperNova sn = new SuperNova(); UseAsOperator(sn); // Use the as operator with a value type. // Note the implicit conversion to int? in // the method body. int i = 5; UseAsWithNullable(i); double d = 9.78654; UseAsWithNullable(d); }
void Awake() { if (instance == null) { instance = this; } }
public void CreateAnimal_WhenCreate_ReturnsTrue() { Giraffe giraffe = giraffeFactory.CreateAnimal() as Giraffe; Assert.True(giraffe.Age < 31); Assert.True(giraffe.Age > 0); }
public void OneFromListComponent() { MainCage mc = new MainCage(); Animal wolf = new Wolf(); Animal bear = new Bear(); Animal giraffe = new Giraffe(); List <ICageComponent> components = new List <ICageComponent>(); components.Add(wolf); components.Add(bear); components.Add(giraffe); int number = 0; int weight = 50; ICageComponent component; mc.AddAnimal(weight); component = mc.isOne(number); foreach (var expected in components) { if (expected.GetType() == component.GetType()) { Assert.AreEqual(expected.GetType(), component.GetType()); } } }
public void Add_new_object_returned_weight_checked() { Animal expected = new Giraffe("Ben", 300); Animal actual = cr.Add(cr.Name, cr.Weight); Assert.AreEqual(expected.weight, actual.weight); }
void Awake() { mApplicationIsQuitting = false; mDirty = false; mTransform = GetComponent <Transform>(); if (mTransform.parent == null) { Debug.LogException(new Exception("A Giraffe Layer must be attached to a GameObject who's parent contains the Giraffe MonoBehaviour"), this); } Transform parent = mTransform.parent; mGiraffe = parent.GetComponent <Giraffe>(); if (mGiraffe == null) { Debug.LogException(new Exception("The parent GameObejct of this Giraffe Layer does not contain a Giraffe monobehaviour"), this); } mesh = new Mesh(); if (mScale <= 0) { mScale = 1; } }
public void Creature_SetName_IsCorrect() { Creature creature = new Giraffe(); creature.setName("Frank"); Assert.AreEqual(creature.getName(), "Frank"); }
public static void Main() { Animal herman = new Lion(); Animal zelda = new Giraffe(); Animal don = new Duck(); Animal[] three = {herman, zelda, don}; Feed(three); }
public void SaySomethingTest() { var animal = new Giraffe("test", 5); var result = animal.SaySomething(); Assert.AreEqual("Giraffe test said hello", result); }
public static void Main() { Lion herman = new Lion(); Giraffe zelda = new Giraffe(); Animal[] two = {herman, zelda}; Feed(two); herman.Attack(); }
public IActionResult Create(Giraffe giraffe) { giraffe.Id = Guid.NewGuid(); giraffe.Name = giraffe.Name; giraffe.PicId = giraffe.PicId; DbContext.Giraffes.Add(giraffe); return(Redirect("https://localhost:44338/Giraffes")); }
public void WakeUpTest() { var animal = new Giraffe("test", 1); animal.NightNight(); animal.WakeUp(); Assert.IsFalse(animal.IsSleeping); }
public void TotalCostCounter(Booking booking, Giraffe giraffe) { var timeBooked = booking.To.Subtract(booking.From).TotalHours; var costBooked = (timeBooked * giraffe.Price); var costBookedInt = Convert.ToInt32(costBooked); booking.TotalCost = costBookedInt; }
static void Main(string[] args) { Giraffe g = new Giraffe(); FeedMammals(g); TestForMammals(g); SuperNova sn = new SuperNova(); TestForMammals(sn); }
public static void Main() { object b = new Giraffe(); Console.WriteLine(b is Animal); // output: True Console.WriteLine(b.GetType() == typeof(Animal)); // output: False Console.WriteLine(b is Giraffe); // output: True Console.WriteLine(b.GetType() == typeof(Giraffe)); // output: True }
public void VoiceGiraffe() { MainCage mc = new MainCage(); Animal giraffe = new Giraffe(); string expected = "It's a GIRAFFE!"; string v = giraffe.Voice(); Assert.AreEqual(expected, v); }
public GiraffeChildrenCageTestClass() { adultGiraffeCageFactory = new AdultGiraffeCageFactory(); childrenGiraffeCageFactory = new ChildrenGiraffeCageFactory(); giraffeFactory = new GiraffeFactory(); giraffeAdultCage = adultGiraffeCageFactory.CreateCage() as GiraffeAdultCage; giraffeChildrenCage = childrenGiraffeCageFactory.CreateCage() as GiraffeChildrenCage; giraffe = giraffeFactory.CreateAnimal() as Giraffe; }
private void _gotoNext() { _puzzleIndex++; if (_puzzleIndex >= Puzzles.Length) { Giraffe.Quit(); } else { Goto(Puzzles[_puzzleIndex]); } }
private static void BrokenArrayCovariance() { try { Animal[] animals = new Giraffe[10]; animals[0] = new Turtle(); } catch (ArrayTypeMismatchException ex) { Console.WriteLine(String.Format("Illegal:\n{0}\n\n", ex.ToString())); } }
public static void Main() { object b = new Giraffe(); Console.WriteLine("b is Animal: {0}", b is Animal); Console.WriteLine("b.GetType() == typeof(Animal): {0}", b.GetType() == typeof(Animal)); Console.WriteLine("--------------------------------------"); Console.WriteLine("b is Giraffe: {0}", b is Giraffe); Console.WriteLine("b.GetType() == typeof(Giraffe): {0}", b.GetType() == typeof(Giraffe)); }
public IActionResult Delete(Giraffe giraffe) { var giraffeToDelete = DbContext.Giraffes.FirstOrDefault(g => g.Id == giraffe.Id); if (giraffeToDelete == null) { return(NotFound()); } DbContext.Giraffes.Remove(giraffeToDelete); return(RedirectToAction("Index")); }
public void TestMethod1() { Giraffe giraffe = new Giraffe(); giraffe.Move(); Wolf wolf = new Wolf(); wolf.Move(); wolf.MakeSound(); Dog dog = new Dog(); dog.MakeSound(); }
public void method() { // Create a new derived type. Giraffe g = new Giraffe(); // Implicit conversion to base type is safe. Animal a = g; // Explicit conversion is required to cast back // to derived type. Note: This will compile but will // throw an exception at run time if the right-side // object is not in fact a Giraffe. Giraffe g2 = (Giraffe)a; }
static void Main(string[] args) { Giraffe g = new Giraffe(); FeedMammals(g); TestForMammals(g); // Use the as operator to test // an incompatible type. SuperNova sn = new SuperNova(); TestForMammals(sn); }
public InMemoryZooDb() { this.animals = new List <Animal>(); for (int i = 0; i < 10; i++) { var monkey = new Monkey(); var gireffe = new Giraffe(); var bear = new Bear(); this.animals.Add(monkey); this.animals.Add(gireffe); this.animals.Add(bear); } }
private void OnTriggerStay(Collider other) { if (triggered) { return; } Giraffe n = other.transform.root.GetComponent <Giraffe>(); if (n != null && allTargetItemsCrossed) { triggered = true; StartCoroutine(Confetti()); } }
public IActionResult Edit(Giraffe giraffe) { if (ModelState.IsValid) { var giraffeIndex = DbContext.Giraffes.FindIndex(g => g.Id == giraffe.Id); if (giraffeIndex == -1) { return(NotFound()); } DbContext.Giraffes[giraffeIndex] = giraffe; return(RedirectToAction(nameof(Index))); } return(View(giraffe)); }
public ZooTest() { zoo = Lab2Zoo.Models.Factories.ZooFactory.CreateZoo(); giraffeCageFactory = new GiraffeCageFactory(); giraffeFactory = new GiraffeFactory(); bearFactory = new BearFactory(); bearCageFactory = new BearCageFactory(); giraffe = giraffeFactory.CreateAnimal() as Giraffe; bear = bearFactory.CreateAnimal() as Bear; giraffeCage = giraffeCageFactory.CreateCage() as GiraffeCage; bearCage = bearCageFactory.CreateCage() as BearCage; zoo.Add(giraffeCage); zoo.Add(bearCage); giraffeCage.Add(giraffe); bearCage.Add(bear); }
static void Main(string[] args) { var g = new Giraffe(); var a = new Animal(); FeedMammals(g); FeedMammals(a); // Output: // Eating. // Animal is not a Mammal SuperNova sn = new SuperNova(); TestForMammals(g); TestForMammals(sn); // Output: // I am an animal. // SuperNova is not a Mammal }