Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics Methods Method Parameters

This works on C# method basics

This code returns the correct answer but they ask for the method to be type void. I run this in my IED and it runs......

Program.cs
using System;

class Program
{

 static double Multiply(double valueOne, double valueTwo)
        {


           return valueOne * valueTwo;

        }

        static void Main(string[] args)
        {
            Console.WriteLine(Multiply(1, 2));
            Console.WriteLine(Multiply(4 ,6));


        }

}

2 Answers

@teamtreehouse should fix this error thrown unless there is some way to return a double type to a void type that I am unaware of.

Hi Joseph,

In your method you should remove the double keyword and add the void keyword. Then between curly braces you add Console.WriteLine(valueOne*valueTwo); and remove the return line. That way you are not returning anything, hence why the method is void.

Code should look like this :

using System;

class Program
{

    // YOUR CODE HERE: Define a method named Multiply. Remember
    // to use the "static" and "void" keywords: "static void
    // Multiply" (without quotes). Multiply should take two
    // "double" values as parameters.

    static void Multiply(double x, double y)
    {
        Console.WriteLine(x*y);
    }


    static void Main(string[] args)
    {
        // YOUR CODE HERE:
        // Call Multiply with two arguments: 2.5 and 2.
        Multiply(2.5, 2);
        // YOUR CODE HERE:
        // Call Multiply with two arguments: 6 and 7.
        Multiply(6, 7);
    }

}

Hope this explains it for you.