[Deep learning C #] input and output security--change security for variable type parameter lists

Source: Internet
Author: User

Variable type parameter list (*variant-type-parameter-lists)

The mutable type parameter list (variant-type-parameter-lists ) can only appear on interfaces and delegate types. It differs from ordinary type-parameter-lists in that it can precede each type parameter with a variable annotation: in and out.
If the preceding change annotation is out , the type parameter becomes a covariant type parameter, and if the change annotation is in, the type parameter becomes the contravariant type parameter , or if there is no change annotation, the type parameter is said to be fixed type parameter .
For example:

interface C<out x ,in y ,z>{    x M(x,y);    z P{get;set;}}

In the preceding code, X is the covariant type parameter, Y is the contravariant type parameter, and z is a fixed type parameter.
  

Type parameter change security

Changing annotations in the type parameter list of a type restricts where the type can appear in the type declaration. The type T is output unsafe (output-unsafe) if one of the following conditions is true:
T is contravariant type parameter
T is an array type that has an output unsafe element type
T is a s< A1 from a generic type,... AK > Constructed interface or delegate type s< X1,.. XK; where, for at least one Ai, one of the following conditions exists:
Xi is covariant or fixed, and the Ai is output insecure.
Xi is contravariant or fixed, while Ai is input safe.
The type T is input insecure (input-unsafe) if one of the following conditions is true:
T is a covariant type parameter
T is an array type that has input unsafe element types
T is a s< A1 from a generic type,... AK > Constructed interface or delegate type s< X1,.. XK; where, for at least one Ai, one of the following conditions exists:
Xi is covariant or fixed, and Ai is unsafe for input.
Xi is contravariant or fixed, and the Ai is output unsafe.
Intuitively, the output unsafe type should be disabled at the output location, and the input unsafe type is forbidden at the input location.
If the type is not output insecure, it is output safe (output-safe) and is input safe (input-safe) if it is not input insecure. That is, the security of the input and output does not exist in a state other than security and insecurity.

What is a type parameter

A class definition can specify a set of type parameters by adding a list of type parameter names enclosed in angle brackets after the class name. The type parameter can be used to define the members of a class in the class declaration body. In the following example, the type parameter for Pair is TFirst and Tsecond:

publicclass Pair<TFirst,TSecond>{    public TFirst First;    public TSecond Second;}

  the class type to declare as taking a type parameter is called a generic class type . struct types, interface types, and delegate types can also be generics. When you use a generic class, you must provide type arguments for each type parameter:

pair  <  int,string  >  pair  =  new  pair  <  int,string  >  {First =  1 , Second =  "II"};int I =  pair   First; //TFirst is int  string  s =  pair   Second; //Tsecond is string  

A generic type that provides type arguments (such as pair< int,string > above) is called a constructed type.

[Deep learning C #] input and output security--change security for variable type parameter lists

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.