- C# 7 and .NET Core 2.0 High Performance
- Ovais Mehboob Ahmed Khan
- 99字
- 2021-08-27 18:47:11
Creating Local Functions
Functions that are created within a function are known as Local Functions. These are mainly used when defining helper functions that have to be in the scope of the function itself. The following example shows how the factorial of the number can be obtained by writing a Local Function and calling it recursively:
static void Main(string[] args) { Console.WriteLine(ExecuteFactorial(4)); } static long ExecuteFactorial(int n) { if (n < 0) throw new ArgumentException("Must be non negative",
nameof(n)); else return CheckFactorial(n); long CheckFactorial(int x) { if (x == 0) return 1; return x * CheckFactorial(x - 1); } }
推薦閱讀
- 數(shù)據(jù)存儲(chǔ)架構(gòu)與技術(shù)
- 復(fù)雜性思考:復(fù)雜性科學(xué)和計(jì)算模型(原書(shū)第2版)
- Game Development with Swift
- 區(qū)塊鏈:看得見(jiàn)的信任
- 大數(shù)據(jù)時(shí)代下的智能轉(zhuǎn)型進(jìn)程精選(套裝共10冊(cè))
- 大數(shù)據(jù)架構(gòu)商業(yè)之路:從業(yè)務(wù)需求到技術(shù)方案
- 企業(yè)級(jí)容器云架構(gòu)開(kāi)發(fā)指南
- INSTANT Android Fragmentation Management How-to
- 區(qū)塊鏈技術(shù)應(yīng)用與實(shí)踐案例
- 數(shù)字IC設(shè)計(jì)入門(mén)(微課視頻版)
- Oracle 11g+ASP.NET數(shù)據(jù)庫(kù)系統(tǒng)開(kāi)發(fā)案例教程
- SQL Server 2008寶典(第2版)
- 利用Python進(jìn)行數(shù)據(jù)分析(原書(shū)第2版)
- 數(shù)據(jù)挖掘與數(shù)據(jù)化運(yùn)營(yíng)實(shí)戰(zhàn):思路、方法、技巧與應(yīng)用
- MySQL核心技術(shù)手冊(cè)