---
title: "Delegate for any method type - C#"  
description: "Delegate for any method type - C#"  
author: "Anonymous User"  
published: 2013-04-06  
updated: 2013-04-06  
canonical: https://www.mindstick.com/forum/726/delegate-for-any-method-type-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Delegate for any method type - C#

Hi Everyone!\
I want to have a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) that will [execute](https://www.mindstick.com/interview/49/how-can-i-execute-a-php-script-using-command-line) any [external](https://www.mindstick.com/articles/12810/how-to-connect-tablet-to-external-monitor-or-flat-screen-tv-using-computer-adapters) [method](https://www.mindstick.com/forum/166/webservice-method), like this:\
class CrazyClass{ //other [stuff](https://www.mindstick.com/interview/33816/what-is-stuff-function-is-sql-server)\
[public](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) AnyReturnType Execute(AnyKindOfMethod Method, object[] ParametersForMethod) { //more stuff return Method([Parameters](https://www.mindstick.com/articles/87/passing-parameters-in-c-sharp)) //or something like that }}\
Is this possible? Is there a [delegate](https://www.mindstick.com/articles/777/delegate-and-event-in-c-sharp) that takes any method [signature](https://www.mindstick.com/interview/516/explain-about-xml-signature)?

## Replies

### Reply by Vijay Shukla

Hi!\
Try this way\

```
public object Execute(MethodInfo mi, object instance = null, object[] parameters = null){    return mi.Invoke(instance, parameters);}
```

\
\

### Reply by AVADHESH PATEL

Hi Goti!\
tTy different way by Func<T> and closures:\
public T Execute<T>(Func<T> method){ // stuff return method();}The caller can then use closures to implement it:\
var result = yourClassInstance.Execute(() => SomeMethod(arg1, arg2, arg3));\


---

Original Source: https://www.mindstick.com/forum/726/delegate-for-any-method-type-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
