Func<object, String, bool> is generic, you can first think of him as a normal type, such as String
public class func{}//Customize a generic class.
Func filter; Custom Fields
Public Func Filter//property, accessor for last field filter. Type Func
{
Get
{return filter;}
Set
{ }
}
Do not consider Func<object, string, Bool>, the last paragraph of code understand? I'm explaining to you.
The following is a generic type.
If there are several custom classes, each class has a member My_item, but the My_item type is different
Class Func1
{
public int my_item;
}
Class Func2
{
public string My_item;
}
Class Func3
{
public bool My_item;
}
To use the my_item of int, it is necessary to use Func1 My_func = new Func1 ();
To use bool, it is necessary to use Func3 My_func = new Func3 ();
This time it shows the usefulness of generics:
Class func<t>
{
Public T My_item; In terms of the class definition, T is an unknown type.
}
This is the generic, which is when you defer specifying a type to a client code declaration and instantiate the class or method.
As the name implies, generics, is said to be a wide range of types, the public T my_item in the type T, may be an int or a string, it could be a list, or an array, etc.
All in all, it could be any type.
How do you know what kind of a t is? The one with the edge: defer specifying a type to a client code declaration and instantiate the class or method
The following code declares and instantiates a func<t>
You can think of T as a variable that only accepts the class name.
func<int> My_func = new func<int>;
At this time, the class member public T My_item is actually the public int my_item
That is, replace all class definitions inside T with declarations and instantiations of the <> inside type.
func<string> My_func = new func<string>;
At this time, the class member public T My_item is actually the public string My_item
We re-define the generic extension of the class:
Class Func<t1, T2, t3>
{
Public T1 my_item1;
Public T2 my_item2;
Public T3 my_item3;
}
Then we define a member My_func in the other class:
Func<int, Object, textbox> My_func;
Thus, my_item1 is an int, my_item2 is an object, and My_item3 is a TextBox control.
Then, define the attribute My_func and set the accessors for the My_func:
Public Func<int, Object, textbox> My_func
{
get{}
set{}
}
In fact, in a word, the function of generics is to declare and instantiate a class instance, the type as a parameter.
For example List<string> List
The list inside is a collection of string types.
Besides, it's just generics, not delegates.
The second line declares that the filter is obviously the filter's accessor, and if the filter is a delegate, add an accessor to it and you can compile the past.
If it is a delegate, do you have to add the delegate to the listbox to show it?
C # generic Func<object, String, bool> filter