Thursday 6 June 2019

C# - Fix Error - There is no argument given that corresponds to the required formal parameter

  There is no argument given that corresponds to the required formal parameter 'r'

watch solution on YouTube

2 comments:

  1. Make a separate class for your shape class variables without any methods.

    Example:

    public class Shape
    {
    public double base {get; set;}
    public double height {get; set;}
    }

    public class Square : Shape
    {
    Square(double b, double h)
    {
    base = b;
    height = h;
    }
    public double Area()
    {
    return base * height;
    }
    }

    public class Triangle
    {
    Triangle(double b, double h)
    {
    base = b;
    height = h;
    }
    public double Area()
    {
    return (base * height) / 2;
    }
    }

    // Running it

    class Program
    {
    static void Main(string[] args)
    {
    Shape square = new Shape(10,10);
    Triangle triangle = new Triangle(25, 10);
    Circle circle = new Circle(5);


    Console.WriteLine("Square Area: {0}" , square.Area());
    Console.WriteLine("Triangle Area: {0}", triangle.Area());
    Console.WriteLine("Circle Area: {0}" , circle.Area());
    }
    }

    /* Output

    Square Area: 100
    Triangle Area: 125
    */

    ReplyDelete
    Replies
    1. Email me if you have any questions

      malachias.harris23@gmail.com

      Delete