Lets say i have a method
public static void Blah(object MyMethod) { // i dont know what to replace object with
MyMethod; // or however you would use the variable
}
so basically i need to be able to reference a method through a variable
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re looking for a delegate.
Usage:
Or using lambda syntax (if
DoSomethingwas a Hello World):There is also shortcut syntax available for Delegates in the form of
ActionandFunctypes:And if you need to return a value from your delegate(like an
intin my example) you can use:NOTE: Action and Func provide generic overloads that allow parameters to be passed.