Re: my first class - getting an error

Tech-Archive recommends: Speed Up your PC by fixing your registry



On Mon, 10 Sep 2007 16:36:21 -0700, vinnie <centro.gamma@xxxxxxxxx>
wrote:

I did my first project with the classes, but i get an error that i
don't understand, and so don't know how to correct it.

The error is :
"Error 1 'mixed_class.Program' does not contain a definition for
'Calculus' and no extension method 'Calculus' accepting a first
argument of type 'mixed_class.Program' could be found (are you missing
a using directive or an assembly reference?) C:\Documents and Settings
\Robert\Desktop\prova VS8\mixed_class\Program.cs 20 20 mixed_class"



This is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mixed_class
{
public class Program
{
public static void Main(string[] args)
{
double c = 0;
Console.WriteLine(" Program for calculating the sum");
Console.WriteLine();
Console.WriteLine(" Insert first value:...");
double a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(" Insert the second value:... ");
double b = Convert.ToDouble(Console.ReadLine());
Here an instance of type Program is created.
Program So = new Program();
This won't work because the Program class does not have a Calculus
method. The previous line should apparently instantiate an instance of
the summing class.
c = So.Calculus(3, 4);
Console.WriteLine(" The sum is: {0}", c);
Console.ReadLine();
}
}
public class summing
{

public double Calculus(double a, double b, out double c)
{
c = a + b;
return c;
}
The return value and the out parameter of method are unneeded
duplicates. This function's signature matches the call to Calculate in
the Program cless' main function.
public double Calculus(double a, double b)
{
double c = a + b;
return c;
}
}
}
regards
A.G.
.