Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error	1	The name 'ProcessAndDisplayNumber' does not exist in the current context	C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2005\Projects\Project-213\Project-213\Program.cs	37	13	Project-213
Error	2	The name 'ProcessAndDisplayNumber' does not exist in the current context	C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2005\Projects\Project-213\Project-213\Program.cs	38	13	Project-213
Error	3	The name 'ProcessAndDisplayNumber' does not exist in the current context	C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2005\Projects\Project-213\Project-213\Program.cs	39	13	Project-213



namespace Project_213
{
   delegate void DoubleOp(double value);
   class MathOperations
    {
        public static void MultiplyByTwo(double value)
        {
            double result = value * 2;
            Console.WriteLine("Multiplying by 2: {0} gives {1}", value, result);
        }
        public static void Square(double value)
        {
            double result = value * value;
            Console.WriteLine("Squaring: {0} gives {1}", value, result);
        }
        
        public static void ProcessAndDisplayNumber(DoubleOp action, double value)
        {
            Console.WriteLine("\nProcessAndDisplayNumber called with value = " + value);
            action(value);
        }
        
    }
           
    class Program
    {        
        static void Main(string[] args)
        {
            DoubleOp operations = new DoubleOp(MathOperations.MultiplyByTwo);
            operations += new DoubleOp(MathOperations.Square);
            ProcessAndDisplayNumber(operations, 2.0);
            ProcessAndDisplayNumber(operations, 7.94);
            ProcessAndDisplayNumber(operations, 1.414);
            Console.WriteLine();
        }
    }
}
Posted
Updated 4-Aug-10 18:17pm
v2

You are calling the ProcessAndDisplayNumber
method which is in a separate class.

Create an instance of the MathOperations class and then call this method using this instance.

Something like -
MathOperations objOperations = new MathOperations();
objOperations.ProcessAndDisplayNumber(operations, 1.414);
 
Share this answer
 
ProcessAndDisplayNumber is a static method of another class, then you should specify the class name before it, as shown below:

C#
MathOperations.ProcessAndDisplayNumber(operations, 1.414);
 
Share this answer
 

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