Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Sfida: Struct | Struct e Enumeratori
C# Oltre le Basi

bookSfida: Struct

Completa gli spazi vuoti per creare una struct chiamata Car che abbia i seguenti attributi:

  1. name di tipo string;
  2. model di tipo int;
  3. mileage di tipo float.

Completa inoltre gli spazi vuoti per terminare l'istruzione di output.

index.cs

index.cs

copy
12345678910111213141516171819202122
using 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."); } }
  1. Utilizzare la parola chiave public prima dei campi nella definizione della struttura.
  2. Utilizzare la sintassi variableName.fieldName per accedere ai campi e ai loro dati.
index.cs

index.cs

copy
12345678910111213141516171819202122
using 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."); } }
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 3

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Suggested prompts:

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

bookSfida: Struct

Scorri per mostrare il menu

Completa gli spazi vuoti per creare una struct chiamata Car che abbia i seguenti attributi:

  1. name di tipo string;
  2. model di tipo int;
  3. mileage di tipo float.

Completa inoltre gli spazi vuoti per terminare l'istruzione di output.

index.cs

index.cs

copy
12345678910111213141516171819202122
using 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."); } }
  1. Utilizzare la parola chiave public prima dei campi nella definizione della struttura.
  2. Utilizzare la sintassi variableName.fieldName per accedere ai campi e ai loro dati.
index.cs

index.cs

copy
12345678910111213141516171819202122
using 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."); } }
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 3
some-alt