What is Action<string>
, how can it be used?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
here is a small and easy introduction of Action:
http://www.c-sharpcorner.com/UploadFile/rmcochran/anonymousMethods04022006141542PM/anonymousMethods.aspx
It is basically just a delegate that does not return a value.
Have a look here: http://msdn.microsoft.com/en-us/library/018hxwa8.aspx
Action<string>
would just be a delegate of a method that excepted a single string parameter and did not return anything.It is a delegate with one parameter, this being a string.
Usefull because it means you do not have to create delegates anymore for actions as long as you can use a standard action for them (i.e. the number of parameters is fixed, no default values and you can just use an existing action).
Action
is a standard delegate that has one to 4 parameters (16 in .NET 4) and doesn't return value. It's used to represent an action.There are other predefined delegates :
Predicate
, delegate that has one parameter and returns a boolean.Func
is the more generic one, it has 1 to 4 parameters (16 in .NET 4) and returns somethingThis is a delegate to a function with the signature
void Bla(string parameter)
. You can use this to pass functions to other functions. For instance you can do thisto print all characters to the console