Meer informatie over types

Opdracht 1

Bepaal of de het Temperature object een class of een struct moet zijn.

Specificaties

  • De waarden van myTemperature moeten in de Main functie niet gewijzigd zijn.

Verwachte output

The temperature 98.6° is a valid body temperature.

Nu jij

using System;
 
________ Temperature
{
    public double Value { get; set; }
}
 
class Program
{
    static bool IsValidBodyTemperature(Temperature temperature)
    {
        if (20 < temperature.Value && temperature.Value < 42)
        {
            return true;
        }
        else
        {
            //maybe in Farenheid, convert it to celcius
            temperature.Value = (temperature.Value - 32) * 5 / 9;
            if (20 < temperature.Value && temperature.Value < 42)
            {
                return true;
            }
            return false;
        }
    }
 
    static void Main()
    {
        Temperature myTemperature = new Temperature() { Value = 98.6 };
        if (IsValidBodyTemperature(myTemperature))
        {
            Console.WriteLine($"The temperature {myTemperature.Value}° is a valid body temperature.");
        }
    }
}

Opdracht 2

Bepaal of de het Car object een class of een struct moet zijn.

Specificaties

  • De waarden van firstCar moeten in de Main functie correct zijn volgens de SetToValidColor functie.

Verwachte output

The T-Ford is available in any color the customer wants, as long as it's black.

Nu jij

using System;
 
________ Car
{
    public string Name { get; set; }
    public string Color { get; set; }
}
 
class Program
{
    static void SetToValidColor(Car car)
    {
        if (car.Name == "T-Ford")
        {
            car.Color = "black";
        }
    }
 
    static void Main()
    {
        Car firstCar = new Car() { Name = "T-Ford", Color = "red" };
        SetToValidColor (firstCar);
        Console.WriteLine($"The {firstCar.Name} is available in any color the customer wants, as long as it’s {firstCar.Color}.");
    }
}