Asp.net| Programming | skills | network
generic type:
Generics Overview: Generics can be applied to classes, methods, structures, interfaces, delegates, and other designs, concurrent reuse, type safety and efficiency in one is with the right on the non-generic type of application generics, you must use the class System.Collections.Generic.Stack. The class is declared in the following way:
System.Collections.Generic.Stack (Declaration code)
You can think of the stack class as having the following schematic processing process:
Stack class schematic code:
public class Stack<>
{
T[] Item;
int count;
public void Push (T item) {}
Public T Pop () {}
}
You can set constraints on 3 types of parameters for generics: Derivation constraints, constructor constraints, reference/value type constraints
anonymous method:
Overview of anonymous methods: In c#1.x, events are implemented using delegates that support calling methods. Delegates provide operators and methods to add or delete a target method, or to the entire. NET Framework is widely used in events, callbacks, asynchronous invocations, multithreading, and so on. However, in order to use a delegate, sometimes having to create a class or method is too cumbersome and inconsistent with the developer's thinking habits. For example, the following example enables you to get simple input from a form that contains list boxes, text boxes, and buttons. When you press the button, the text in the text box is added to the list box. In c#1.x, you use a delegate to implement the event mechanism, as shown in the following code
Using the c#1.x implementation code
Class Inputform:from
{
ListBox listbox;
TextBox textbox;
Button AddButton;
Pulic MyForm ()
{
ListBox = new ListBox ();
TextBox = new TextBox ();
AddButton = new Button ();
}
........
void AddClick (Object Sender,eventargs e)
{
LISTBOX.ITEMS.ADD (TextBox.Text)
}
}
Anonymous methods allow the associated code (usually the method entity) to be "embedded" into the place where the delegate is used, so that both the delegate and the method entity are lumped together
Implementing code with anonymous methods (no parameters)
Class Inputform:from
{
ListBox listbox;
TextBox textbox;
Button AddButton;
Pulic MyForm ()
{
ListBox = new ListBox ();
TextBox = new TextBox ();
AddButton = new Button ();
Addbutton.click + = delegate {listBox.Items.Add (textbox.text);}
}
}