Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Refactor a Coordinate Struct | Composition, Inheritance, and Refactoring
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C# OOP Class Construction Drills

bookChallenge: Refactor a Coordinate Struct

Oppgave

Swipe to start coding

Refactor the provided Coordinate struct into a class and add a method to calculate the distance to another Coordinate object.

  • Replace the struct with a class named Coordinate that has X and Y properties.
  • Implement a constructor that accepts values for X and Y.
  • Add a method named DistanceTo that takes another Coordinate object as a parameter and returns the Euclidean distance between the two coordinates.
  • The distance is calculated as the square root of the sum of the squared differences of the X and Y values.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 4
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Can you explain this in simpler terms?

What are the main points I should remember?

Can you give me an example?

close

bookChallenge: Refactor a Coordinate Struct

Sveip for å vise menyen

Oppgave

Swipe to start coding

Refactor the provided Coordinate struct into a class and add a method to calculate the distance to another Coordinate object.

  • Replace the struct with a class named Coordinate that has X and Y properties.
  • Implement a constructor that accepts values for X and Y.
  • Add a method named DistanceTo that takes another Coordinate object as a parameter and returns the Euclidean distance between the two coordinates.
  • The distance is calculated as the square root of the sum of the squared differences of the X and Y values.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 4
single

single

some-alt