Zhuo use of generic language class

Zhuo use of generic language class

 

Generics are very important feature of modern programming languages. C # language can fully define and use generic types. Zhuo language for the majority of non-specialists, in order to reduce the difficulty of programming, did not achieve the definition of a generic type, does not support the generic method definition, but supports the use of generic types.

 

Zhuo language provides a listing is a generic type, its corresponding .NET type is List <T>.

In C #, create a string List of generic instance like this:

var list = new List<string>();

List must be followed to keep one pair of '<>', put in square brackets int, which is the standard C # syntax, written in other languages, too.

Zhuo language and create a list of strings example is written like this:

LB = text list (new)

This program last '(new)' just call the constructor with no arguments, and on a program in C # Final '()' meaning the same brackets Riga 'new' has no real meaning, just to help beginners to understand, We will not see an empty pair of parentheses confused.

 

Here the meaning of 'text list' and 'List <string>' is the same, 'List' corresponding list, 'string' corresponding to the text. But there are two differences:

  1. Different order, Zhuo languages ​​after the generic type generic parameter front, C #, and it is the opposite;
  2. Zhuo language no angle brackets.

What this means is easier to understand.

Think we usually talk, is not it also the 'text' front 'list' in the post, and usually did not speak and write text on the outside angle brackets. So Zhuo language easier to understand, at this writing it is also simple, knowledge point less than C #. Zhuo language compiler may be separated from the intelligent 'text list' a 'text' and 'lists', and then according to the 'list' is a generic type of case, further analysis of the 'text' is a generic parameter, and finally translated into .NET format 'list <text>' ultimately produce IL instruction.

 

Put together a comparison:

Text list, List <string>

List of integers, List <int>

Rectangle list, List <rectangle>

 

Zhuo language is not better way?

Guess you like

Origin www.cnblogs.com/tkt2016/p/11441750.html