F # Study Notes (1/n)

Source: Internet
Author: User
Tags bitwise operators

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.

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.