Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Error	1	Cannot implicitly convert type 'void' to 'double'	C:\Program.cs	56	28	Project-213

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

namespace Wrox.ProCSharp.Delegates
{
   class MathOperations
   {
      public static double MultiplyByTwo(double value)
      {
         return value * 2;
      }

      public static double Square(double value)
      {
         return value * value;
      }
   }


   delegate double DoubleOp(double x);

   class MainEntryPoint
   {
      static void Main()
      {
         DoubleOp[] operations =
            {
               MathOperations.MultiplyByTwo,
               MathOperations.Square
               //new DoubleOp(MathOperations.MultiplyByTwo),
               //new DoubleOp(MathOperations.Square)
            };

         for (int i = 0; i < operations.Length; i++)
         {
            Console.WriteLine("Using operations[{0}]:", i);
            ProcessAndDisplayNumber(operations[i], 2.0);
            ProcessAndDisplayNumber(operations[i], 7.94);
            ProcessAndDisplayNumber(operations[i], 1.414);
            Console.WriteLine();
         }
      }

      static void ProcessAndDisplayNumber(DoubleOp action, double value)
      {
         double result = action(value);
         Console.WriteLine(
            "Value is {0}, result of operation is {1}", value, result);
      }
   }
}
Posted
Updated 5-Aug-10 19:02pm
v2
Comments
Toli Cuturicu 6-Aug-10 3:34am    
Reason for my vote of 1
Homework - delegates
Alan N 6-Aug-10 4:29am    
Could you let us know which line is line 56 as you only show 48 lines.
Smithers-Jones 6-Aug-10 7:50am    
Reason for my vote of 1
Do you have a question?

What do you mean 'same error' ? What line ? I assume the first line of 'ProcessAndDisplayNumber' ? Where is DobleOp defined ? No-where I can see, but it is plainly defined to return void.
 
Share this answer
 
Looks like you have asked something earlier and did the changes according to some answer. If so, use the same old question and use 'Add Comment' feature to respond back to that reply raising your concern, telling them your observation.
 
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