Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a C# method return a method?

Can a method in C# return a method?

A method could return a lambda expression for example, but I don't know what kind of type parameter could I give to such a method, because a method isn't Type. Such a returned method could be assigned to some delegate.

Consider this concept as an example:

public <unknown type> QuadraticFunctionMaker(float a , float b , float c) {     return (x) => { return a * x * x  + b * x + c; }; }  delegate float Function(float x); Function QuadraticFunction = QuadraticFunctionMaker(1f,4f,3f); 
like image 629
Miro Avatar asked Jul 03 '11 14:07

Miro


People also ask

Do AC recharge cans work?

Are Air Conditioning Recharge Kits Worth It? No, they are not because they don't fix broken AC systems. Instead, they simply recharge refrigerant and leave the cause of the problem unattended. So while a recharge may get cool air blowing again, it masks the real issue as it worsens.

Should I use AC for heat?

You can use the a/c compressor while controlling the heat setting of the car to control the climate within. Doing so will help dehumidify the air, reducing fogged up windows. Running the air conditioner will also help clear up window condensation.

How many cans of AC Pro do I need?

Most cars hold between 28 and 32 ounces of refrigerant (or about 2—3 12oz cans), however larger vehicles and those with rear A/C will likely hold more. Check your vehicle manual for the system capacity for your specific vehicle.

Are all AC recharge kits the same?

AC recharge kits come in a variety of prices and capabilities. Some are just refrigerant in a can with a hose and a gauge. Others include supplies to diagnose issues beyond a low refrigerant pressure and make further repairs. Some of those can even be used to diagnose and recharge home HVAC systems.


1 Answers

The Types you are looking for are Action<> or Func<>.

The generic parameters on both types determine the type signature of the method. If your method has no return value use Action. If it has a return value use Func whereby the last generic parameter is the return type.

For example:

public void DoSomething()                          // Action public void DoSomething(int number)                // Action<int> public void DoSomething(int number, string text)   // Action<int,string>  public int DoSomething()                           // Func<int> public int DoSomething(float number)               // Func<float,int> public int DoSomething(float number, string text)  // Func<float,string,int> 
like image 128
Zebi Avatar answered Sep 20 '22 21:09

Zebi