官术网_书友最值得收藏!

  • .NET Core 2.0 By Example
  • Rishabh Verma Neha Shrivastava
  • 190字
  • 2021-06-24 18:30:59

F# functions

F# functions act like variables. We can declare and use them in the same way as we use variables in C#. A function definition starts with the let keyword, followed by the function name and parameters, a colon, its type, and the right-side expression, showing what the function does. The syntax is follows:

Let functionName parameters [ : returnType] = functionbody

In the preceding syntax:

  • functionName is an identifier of the function.
  • parameters gives the list of parameters separated by spaces. We can also specify an explicit type for each parameter and if not specified, the compiler tends to presume it from the function body as variables.
  • functionbody comprises an expression, or a compound expression, which has number of expressions. The final expression in the function body is the return value.
  • returnType is a colon followed by a type and it is optional. If the returnType is not specified, then the compiler determines it from the final expression in the function body.

Have a look at the following example for our syntax: 

let addValue (x : int) = 5 + x
主站蜘蛛池模板: 上饶市| 阿坝县| 黄大仙区| 丹棱县| 宁陕县| 北辰区| 平顶山市| 平果县| 广宗县| 泰兴市| 甘南县| 突泉县| 建昌县| 石柱| 镇雄县| 公主岭市| 中阳县| 桃园市| 楚雄市| 黑水县| 嘉兴市| 马公市| 炉霍县| 祁门县| 治多县| 遂川县| 苗栗县| 余干县| 碌曲县| 鄱阳县| 宁国市| 新竹县| 木兰县| 南阳市| 镇雄县| 永定县| 峨眉山市| 惠安县| 津市市| 象州县| 凯里市|