Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi , Below is my program, I am getting a error in my main method that Testclass does not contain a method with 6 arguments I am unable to figure out why this happening

C#
using System;
class TestClass
{
    public void ArithematicOperation(int M1, int M2, int M3, int M4, int M5, out double avg)
    {

        avg=M1+M2+M3+M4+M5/5;
    }

}

class Program
{
    static void Main(string[] args)
    {

        int M1 = 10;
        int M2 = 20;
        int M3 = 30;
        int M4 = 40;
        int M5 = 50;

        double avg;

        TestClass t1 = new TestClass(M1, M2, M3, M4, M5, out avg);

    }
}
Posted

Hai,


You passing argument to constructor.


so try this code...

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int M1 = 10;
            int M2 = 20;
            int M3 = 30;
            int M4 = 40;
            int M5 = 50;

            double avg;

            TestClass t1 = new TestClass();
            t1.ArithematicOperation(M1, M2, M3, M4, M5, out avg);

        }
    }
    class TestClass
    {
        public void ArithematicOperation(int M1, int M2, int M3, int M4, int M5, out double avg)
        {

            avg = M1 + M2 + M3 + M4 + M5 / 5;
        }

    }
}
 
Share this answer
 
Comments
ShaHam11 31-Mar-14 8:42am    
Thank you for reply
You have a big misunderstanding about class and member methods.
What have you done is try to create a new TestClass with 6 parameters, where TestClass only has a default constructor, that have no parameters at all.
And what you have to do is creating the TestClass, than calling it's method...
C#
TestClass t1 = new TestClass();
TestClass.ArithematicOperation(M1, M2, M3, M4, M5, out avg);
 
Share this answer
 
Comments
ShaHam11 31-Mar-14 8:42am    
Thank you , Yes i relized it i am passing argument to a constructor.
Kornfeld Eliyahu Peter 31-Mar-14 8:45am    
Glad you got it :-)...
The code in Main is attempting to call a constructor of TestClass with 6 arguments.
The code in TestClass defines a method with 6 arguments.

To call the method as defined, use:
C#
TestClass t1 = new TestClass();
t1.ArithmeticOperation(M1, M2, M3, M4, M5, out avg);
 
Share this answer
 
Comments
ShaHam11 31-Mar-14 8:42am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900