Arithmetic Operations
F # basic data types and C # are very similar, for example, doule corresponds to System in CLR . double type. Note that there are three data types in F # : bigint , bignum and Unit . bigint is an arbitrary large integer equivalent to math. bigint , you must add " I " suffix. bignum is a rational number of any precision, equivalent to math. bignum type. You must add the suffix " n " after the value. Unit indicates that there is only one value type, and " () ", corresponding . net name: core. unit .
Operator
Besides common4And%The remainder operator also has the"-"Negative number operator, for example-(5 + 6) The output is-11.
AboveCodeDemonstrate how to define different types of parameters and returned values.
FirstAddresultBothIntType. The second definition containsAParameter usageFloatType. To ensure precision integrity, the entire function returnsFloatType. The third is the second explicit return type definition.
Bitwise operators
Operator |
Description |
C # |
& |
bitwise AND computation |
& |
|| |
bitwise OR operation |
| |
^ |
exclusive or operation |
^ |
~~~ |
complement by bit |
~ |
|
left shift operator |
|
>>> |
Right Shift Operator |
> |
Simple string operations
F #The string type is in. NetType is simplified, and its storage form is a setUnicode UTF-16Character Sequence. Since it is a character sequence, we can access any character in it through the index pointer. When using stringsC #In addition to common expressions"ABC" BThis expression is used to represent strings.ABCConvertByte []Array.
If you want to indicate the charactersCharType, likeC #Use single quotes, suchLet mychar = 'a ';;.
F #Transfer characters are also supported.C #There is no syntax difference. For example"" R"Enter,"" Udddd"IndicatesUnicodeEncoding,"" Udddddddd"LengthUnicodeEncoding (whereDNumber ).
String Support+You can also directly useStringbuilderClassAppendString.
Once a string is created, you cannot modify its content by indexing it. As shown in:
The following shows how to useStringbuilderTo construct strings of an indefinite length.
initialize the above Code st variable is a stringbuilder type. You can use the append append a string by using the tostring method.