Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Udfordring: Metoder | Section
Practice
Projects
Quizzes & Challenges
Quizzer
Challenges
/
C# Ud Over Det Grundlæggende

bookUdfordring: Metoder

Stryg for at vise menuen

Udfyld de manglende felter for at oprette en metode, der beregner arealet af en cirkel og returnerer værdien.

index.cs

index.cs

copy
123456789101112131415161718192021222324252627282930313233
using System; public class ConsoleApp { class Point { public double x; public double y; } class Circle { public double radius; public Point center; ___ ___ ___() { // The formula is: pi . r . r // The value of pi is 3.14 // r is the radius ___ ___ * ___* radius; } } public static void Main(string[] args) { Point p = new Point(); p.x = 15; p.y = 15; Circle circle = new Circle(); circle.radius = 10; circle.center = p; Console.WriteLine($"Area of the circle with center at ({circle.center.x}, {circle.center.y}) and radius of {circle.radius} is {circle.area()}"); } }
  1. Metoden returnerer en double-værdi.
  2. Sørg for, at metoden bruger nøgleordet public.
index.cs

index.cs

copy
123456789101112131415161718192021222324252627282930313233
using System; public class ConsoleApp { class Point { public double x; public double y; } class Circle { public double radius; public Point center; public double area() { // The formula is: pi . r . r // The value of pi is 3.14 // r is the radius return 3.14 * radius * radius; } } public static void Main(string[] args) { Point p = new Point(); p.x = 15; p.y = 15; Circle circle = new Circle(); circle.radius = 10; circle.center = p; Console.WriteLine($"Area of the circle with center at ({circle.center.x}, {circle.center.y}) and radius of {circle.radius} is {circle.area()}"); } }
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 29

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Sektion 1. Kapitel 29
some-alt