Sfida: Struct
Completa gli spazi vuoti per creare una struct chiamata Car
che abbia i seguenti attributi:
name
di tipostring
;model
di tipoint
;mileage
di tipofloat
.
Completa inoltre gli spazi vuoti per terminare l'istruzione di output.
index.cs
12345678910111213141516171819202122using System; struct ___ { ___; ___; ___; } class Program { static void Main(string[] args) { Car car; car.model = 2023; ___ = "Hilux"; car.mileage = 2000; Console.WriteLine($"The {car.name} has a mileage of {___} miles."); } }
- Utilizzare la parola chiave
public
prima dei campi nella definizione della struttura. - Utilizzare la sintassi
variableName.fieldName
per accedere ai campi e ai loro dati.
index.cs
12345678910111213141516171819202122using System; struct Car { public string name; public int model; public float mileage; } class Program { static void Main(string[] args) { Car car; car.model = 2023; car.name = "Hilux"; car.mileage = 2000; Console.WriteLine($"The {car.name} has a mileage of {car.mileage} miles."); } }
Grazie per i tuoi commenti!
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Can you show me the correct way to define the Car struct?
What should the output statement look like for displaying the Car attributes?
Can you provide an example of how to create and use a Car struct?
Awesome!
Completion rate improved to 2.04
Sfida: Struct
Scorri per mostrare il menu
Completa gli spazi vuoti per creare una struct chiamata Car
che abbia i seguenti attributi:
name
di tipostring
;model
di tipoint
;mileage
di tipofloat
.
Completa inoltre gli spazi vuoti per terminare l'istruzione di output.
index.cs
12345678910111213141516171819202122using System; struct ___ { ___; ___; ___; } class Program { static void Main(string[] args) { Car car; car.model = 2023; ___ = "Hilux"; car.mileage = 2000; Console.WriteLine($"The {car.name} has a mileage of {___} miles."); } }
- Utilizzare la parola chiave
public
prima dei campi nella definizione della struttura. - Utilizzare la sintassi
variableName.fieldName
per accedere ai campi e ai loro dati.
index.cs
12345678910111213141516171819202122using System; struct Car { public string name; public int model; public float mileage; } class Program { static void Main(string[] args) { Car car; car.model = 2023; car.name = "Hilux"; car.mileage = 2000; Console.WriteLine($"The {car.name} has a mileage of {car.mileage} miles."); } }
Grazie per i tuoi commenti!