---
title: "Dynamically invoke method in c#"  
description: "Dynamically invoke method in c#"  
author: "Anonymous User"  
published: 2013-03-05  
updated: 2013-03-05  
canonical: https://www.mindstick.com/forum/620/dynamically-invoke-method-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Dynamically invoke method in c#

Hi Everyone!

I want to be able to [store](https://www.mindstick.com/articles/13125/tips-to-increase-sales-of-your-woocommerce-store) [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php) and disregard [arguments](https://answers.mindstick.com/qa/92535/what-are-the-different-types-of-arguments) until it actually is used.

Here's what I'd like for it to look like:

StoreType f=MyFunction;\
.......\
[var](https://www.mindstick.com/forum/33920/what-is-different-var-and-dynamic-types-in-c-sharp) r=f.Invoke(arg1,arg2,arg3) as ReturnType;\
This is kind of like [Action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) and [Func](https://www.mindstick.com/forum/157161/can-elaborate-difference-between-func-vs-action-vs-predicate), but those are [strongly typed](https://www.mindstick.com/forum/298/strongly-typed-view-in-mvc), and I want to be able to declare and use this type without precisely knowing how many arguments and of what types the function will take.

How do I do this in c#?

Thanks!

## Replies

### Reply by AVADHESH PATEL

Hi Ashish!

For the argument count, just pass an array of object containing the arguments.

f.Invoke(new object[]{ arg1, args2, args3, ... });\
For the type use the method

Convert.ChangeType(objectToConvert, destinationType);


---

Original Source: https://www.mindstick.com/forum/620/dynamically-invoke-method-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
