.NET Fiddle

CSharp · Console

/Program.cs

using System;

var vehicle = GetRandomVehicle();

var printed = vehicle switch
{
    Car or Plane => $"You got a {vehicle}",
    Train { Capacity: var cap } => $"You got a train with {cap} seats",
    _ => "You got something else"
};

Console.WriteLine(printed);

static Vehicle GetRandomVehicle() =>
    Random.Shared.Next(0, 3) switch
    {
        0 => new Car("Olive", "Bradley"),
        1 => new Plane(),
        _ => new Train(5000)
    };

record Vehicle;
record Car(string Color, string Type) : Vehicle;
record Train(long Capacity) : Vehicle;
record Plane : Vehicle;
;