Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Practice: Methods | Introduction to Object-Oriented Programming (OOP)
course content

Зміст курсу

C# Beyond Basics

Practice: MethodsPractice: Methods

Fill in the missing blanks to create a method that calculates the area of a circle and returns the value.

cs

index.cs

1. The method returns a double value.
2. Make sure the method uses the public keyword.

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()}");
    }
}    
      

Все було зрозуміло?

Секція 3. Розділ 8
course content

Зміст курсу

C# Beyond Basics

Practice: MethodsPractice: Methods

Fill in the missing blanks to create a method that calculates the area of a circle and returns the value.

cs

index.cs

1. The method returns a double value.
2. Make sure the method uses the public keyword.

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()}");
    }
}    
      

Все було зрозуміло?

Секція 3. Розділ 8
some-alt