C# 7.0 – #4. Local functions

In C# 6.0 there is no way to declare a function which is local to another function, that is a function visible only inside the body in which is declared. The best way to accomplish this is to declare a delegate variable of type Func<T1,TResult> (or one of the several overloads available), ad then use anonymous methods or lambda expression to write the code of the function, as shown here.

// c# 6.0
Func<int, int, int> sum = (k, y) => {
      return k + y;
};

int c = sum(a, b);

This is not an optimal way to use local function, because of some limitations.

C# 7.0 comes with a true local function, and overcomes all the previous limitations.

Here is an example:

int DoSum(int a, int b)
{
   return LocalSum(a, b);

   int LocalSum(int x, int y)
   {
      return x + y;
   }
}

This is a more natural way to declare and use a local function.

532 thoughts on “C# 7.0 – #4. Local functions

  1. Pingback: online drug store
  2. Pingback: buy cialis cheap
  3. Pingback: buy cialis cheap
  4. Pingback: mazhor4sezon
  5. Pingback: filmfilmfilmes
  6. Pingback: online pharmacies
  7. Pingback: cialis from canada
  8. Pingback: canadian drugstore
  9. Pingback: online drug store
  10. Pingback: pharmacy
  11. Pingback: canada rx
  12. Pingback: canadian drugstore
  13. Pingback: canada viagra
  14. Pingback: online pharmacy
  15. Pingback: pharmacy canada
  16. Pingback: drugs for sale
  17. Pingback: Gz92uNNH
  18. Pingback: drugs for sale
  19. Pingback: online pharmacy
  20. Pingback: online pharmacy
  21. Pingback: JXNhGmmt
  22. Pingback: Psikholog
  23. Pingback: netstate.ru
  24. Pingback: Link
  25. Pingback: psy
  26. Pingback: bit.ly
  27. Pingback: cleantalkorg2.ru
  28. Pingback: bucha killings
  29. Pingback: War in Ukraine
  30. Pingback: Ukraine
  31. Pingback: site
  32. Pingback: stats
  33. Pingback: Ukraine-war
  34. Pingback: movies
  35. Pingback: gidonline
  36. Pingback: web
  37. Pingback: film.8filmov.ru
  38. Pingback: video
  39. Pingback: film
  40. Pingback: filmgoda.ru
  41. Pingback: rodnoe-kino-ru
  42. Pingback: confeitofilm
  43. Pingback: stat.netstate.ru
  44. Pingback: sY5am
  45. Pingback: Dom drakona
  46. Pingback: JGXldbkj
  47. Pingback: aOuSjapt
  48. Pingback: ìûøëåíèå
  49. Pingback: psikholog moskva
  50. Pingback: Usik Dzhoshua 2
  51. Pingback: Dim Drakona 2022
  52. Pingback: TwnE4zl6
  53. Pingback: psy 3CtwvjS
  54. Pingback: lalochesia
  55. Pingback: canadian drugs
  56. Pingback: film onlinee
  57. Pingback: drugstore online
  58. Pingback: canada medication
  59. Pingback: northwestpharmacy
  60. Pingback: canada drug
  61. Pingback: online pharmacies
  62. Pingback: 3qAIwwN
  63. Pingback: video-2
  64. Pingback: sezons.store
  65. Pingback: stromectol coupon
  66. Pingback: 000-1
  67. Pingback: 3SoTS32
  68. Pingback: 3DGofO7
  69. Pingback: Northwest Pharmacy
  70. Pingback: canada drugs
  71. Pingback: buy viagra usa
  72. Pingback: rftrip.ru
  73. Pingback: canada pharmacies
  74. Pingback: viagra canada
  75. Pingback: canada pharmacy
  76. Pingback: dolpsy.ru
  77. Pingback: canada medication
  78. Pingback: dose of stromectol
  79. Pingback: mb588.ru
  80. Pingback: newsukraine.ru
  81. Pingback: buy viagra usa
  82. Pingback: drugstore online
  83. Pingback: edu-design.ru
  84. Pingback: tftl.ru
  85. Pingback: canada drugs
  86. Pingback: brutv
  87. Pingback: dose of stromectol
  88. Pingback: site 2023
  89. Pingback: canadian pharmacys
  90. Pingback: canadianpharmacy
  91. Pingback: sitestats01
  92. Pingback: 1c789.ru
  93. Pingback: cttdu.ru
  94. Pingback: canada viagra
  95. Pingback: 1703
  96. Pingback: hdserial2023.ru
  97. Pingback: serialhd2023.ru
  98. Pingback: matchonline2022.ru
  99. Pingback: bit.ly/3OEzOZR
  100. Pingback: bit.ly/3gGFqGq
  101. Pingback: bit.ly/3ARFdXA
  102. Pingback: bit.ly/3ig2UT5
  103. Pingback: bit.ly/3GQNK0J
  104. Pingback: bep5w0Df
  105. Pingback: www
  106. Pingback: icf
  107. Pingback: 24hours-news
  108. Pingback: rusnewsweek
  109. Pingback: uluro-ado
  110. Pingback: canadian rx
  111. Pingback: irannews.ru
  112. Pingback: klondayk2022
  113. Pingback: canadian pharmacys
  114. Pingback: tqmFEB3B
  115. Pingback: drugs for sale
  116. Pingback: 2022-film
  117. Pingback: canadian pharmacy
  118. Pingback: mangalib
  119. Pingback: canadian pharmacy
  120. Pingback: x
  121. Pingback: 9xflix
  122. Pingback: xnxx
  123. Pingback: 123movies
  124. Pingback: canadadrugs
  125. Pingback: buy viagra now
  126. Pingback: canada drugs
  127. Pingback: kinokrad
  128. Pingback: batmanapollo
  129. Pingback: www.dibiz.comgdooc
  130. Pingback: canadian drugs
  131. Pingback: canadianpharmacy
  132. Pingback: vsovezdeisrazu
  133. Pingback: 2023
  134. Pingback: ipsychologos
  135. Pingback: yug-grib.ru
  136. Pingback: studio-tatuage.ru
  137. Pingback: buy viagra 25mg
  138. Pingback: video.vipspark.ru
  139. Pingback: vitaliy-abdulov.ru
  140. Pingback: psychophysics.ru
  141. Pingback: canadian drugstore
  142. Pingback: Kuliah Murah
  143. Pingback: 918kiss
  144. Pingback: pg slot
  145. Pingback: 918kiss
  146. Pingback: ItMe.Xyz
  147. Pingback: Bulk URL Shortener
  148. Pingback: ItMe.Xyz
  149. Pingback: MasumINTL.Com
  150. Pingback: ItMe.Xyz
  151. Pingback: masumintl
  152. Pingback: masumintl.com
  153. Pingback: masumintl

Comments are closed.