Challenge: Structs
Fill in the blanks to create a struct called Car
which has the following attributes:
name
of typestring
;model
of typeint
;mileage
of typefloat
.
Also fill in the blanks to complete the output statement.
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."); } }
- Use the
public
keyword before the fields in the structure definition. - Use the
variableName.fieldName
syntax for accessing the fields and their data.
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."); } }
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 3
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
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
Challenge: Structs
Swipe to show menu
Fill in the blanks to create a struct called Car
which has the following attributes:
name
of typestring
;model
of typeint
;mileage
of typefloat
.
Also fill in the blanks to complete the output statement.
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."); } }
- Use the
public
keyword before the fields in the structure definition. - Use the
variableName.fieldName
syntax for accessing the fields and their data.
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."); } }
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 3