C# 7.0 – #7. An improved expression body feature

In C# 6.0 a read-only property like this:

public string SomeProperty
{
    get { return "sometext"; }
}

can be rewritten in a more compact way:

public string SomeProperty => "sometext";

This feature is called “expression body”, but it has some limitations, e.g. the property is turned into field, it only works with read-only properties and not with constructors, deconstructor, getter, setter and so on.

C# 7.0 add all these constructs and then expands the usage of this feature.

Here’s an example, which was taken “as is” from the .Net blog without any test in development environment because by the time of the last released build of Visual Studio 2017 (15.0.26020.0) this new feature doesn’t work yet:

class Person
{
    private static ConcurrentDictionary<int, string> names = new ConcurrentDictionary<int, string>();
    private int id = GetId();

    public Person(string name) => names.TryAdd(id, name); // constructors

    ~Person() => names.TryRemove(id, out *);              // destructors
    
    public string Name
    {
        get => names[id];                                 // getters
        set => names[id] = value;                         // setters
    }
}

480 thoughts on “C# 7.0 – #7. An improved expression body feature

  1. Pingback: buy viagra usa
  2. Pingback: buy tadalafil
  3. Pingback: buy cialis germany
  4. Pingback: mazhor4sezon
  5. Pingback: canadian drugs
  6. Pingback: canada drug
  7. Pingback: filmfilmfilmes
  8. Pingback: gRh9UPV
  9. Pingback: canada pharmacy
  10. Pingback: gewrt.usluga.me
  11. Pingback: 9-05-2022
  12. Pingback: kinoteatrzarya.ru
  13. Pingback: canadadrugs
  14. Pingback: TopGun2022
  15. Pingback: Xvideos
  16. Pingback: XVIDEOSCOM Videos
  17. Pingback: canadian cialis
  18. Pingback: northwestpharmacy
  19. Pingback: ivanesva
  20. Pingback: canadadrugs
  21. Pingback: Netflix
  22. Pingback: FILM
  23. Pingback: designchita.ru
  24. Pingback: YA-krasneyu
  25. Pingback: design-human.ru
  26. Pingback: designmsu.ru
  27. Pingback: vkl-design.ru
  28. Pingback: irida-design.ru
  29. Pingback: projectio
  30. Pingback: psy online
  31. Pingback: do-posle-psihologa
  32. Pingback: uels ukrain
  33. Pingback: online pharmacy
  34. Pingback: DPTPtNqS
  35. Pingback: qQ8KZZE6
  36. Pingback: D6tuzANh
  37. Pingback: SHKALA TONOV
  38. Pingback: chelovek-iz-90-h
  39. Pingback: 3Hk12Bl
  40. Pingback: 3NOZC44
  41. Pingback: 01211
  42. Pingback: tor-lyubov-i-grom
  43. Pingback: film-tor-2022
  44. Pingback: hd-tor-2022
  45. Pingback: hdorg2.ru
  46. Pingback: canadian pharmacys
  47. Pingback: Psikholog
  48. Pingback: netstate.ru
  49. Pingback: Link
  50. Pingback: buy viagra 25mg
  51. Pingback: psy
  52. Pingback: bit.ly
  53. Pingback: cleantalkorg2.ru
  54. Pingback: bucha killings
  55. Pingback: War in Ukraine
  56. Pingback: Ukraine
  57. Pingback: sildenafil
  58. Pingback: site
  59. Pingback: viagra
  60. Pingback: stats
  61. Pingback: revatio
  62. Pingback: Ukraine-war
  63. Pingback: movies
  64. Pingback: gidonline
  65. Pingback: web
  66. Pingback: film.8filmov.ru
  67. Pingback: video
  68. Pingback: filmgoda.ru
  69. Pingback: rodnoe-kino-ru
  70. Pingback: stat.netstate.ru
  71. Pingback: sY5am
  72. Pingback: Dom drakona
  73. Pingback: JGXldbkj
  74. Pingback: aOuSjapt
  75. Pingback: ìûøëåíèå
  76. Pingback: psikholog moskva
  77. Pingback: Dim Drakona 2022
  78. Pingback: TwnE4zl6
  79. Pingback: psy 3CtwvjS
  80. Pingback: film onlinee
  81. Pingback: canada drug
  82. Pingback: viagra canada
  83. Pingback: buy stromectol
  84. Pingback: stromectol doses
  85. Pingback: 3qAIwwN
  86. Pingback: video-2
  87. Pingback: sezons.store
  88. Pingback: psy-news.ru
  89. Pingback: buy viagra 25mg
  90. Pingback: 000-1
  91. Pingback: 3SoTS32
  92. Pingback: 3DGofO7
  93. Pingback: canada drugs
  94. Pingback: stromectol cvs
  95. Pingback: stromectol reviews
  96. Pingback: drugstore online
  97. Pingback: buy viagra 25mg
  98. Pingback: rftrip.ru
  99. Pingback: cialis from canada
  100. Pingback: dolpsy.ru
  101. Pingback: kin0shki.ru
  102. Pingback: 3o9cpydyue4s8.ru
  103. Pingback: mb588.ru
  104. Pingback: generic stromectol
  105. Pingback: newsukraine.ru
  106. Pingback: edu-design.ru
  107. Pingback: tftl.ru
  108. Pingback: generic stromectol
  109. Pingback: stromectol cvs
  110. Pingback: brutv
  111. Pingback: stromectol pills
  112. Pingback: site 2023
  113. Pingback: pharmacy canada
  114. Pingback: canadadrugs
  115. Pingback: buy viagra now
  116. Pingback: sitestats01
  117. Pingback: 1c789.ru
  118. Pingback: cttdu.ru
  119. Pingback: canadian rx
  120. Pingback: pharmacy
  121. Pingback: 1703
  122. Pingback: hdserial2023.ru
  123. Pingback: serialhd2023.ru
  124. Pingback: matchonline2022.ru
  125. Pingback: Northwest Pharmacy
  126. Pingback: bit.ly/3OEzOZR
  127. Pingback: bit.ly/3gGFqGq
  128. Pingback: bit.ly/3ARFdXA
  129. Pingback: bit.ly/3ig2UT5
  130. Pingback: bit.ly/3GQNK0J
  131. Pingback: best drugs for ed
  132. Pingback: bep5w0Df
  133. Pingback: www
  134. Pingback: canada pharmacy
  135. Pingback: online drug store
  136. Pingback: icf
  137. Pingback: 24hours-news
  138. Pingback: rusnewsweek
  139. Pingback: uluro-ado
  140. Pingback: irannews.ru
  141. Pingback: klondayk2022
  142. Pingback: gravatar.comkqwsh
  143. Pingback: tqmFEB3B
  144. Pingback: canadian viagra
  145. Pingback: 2022-film
  146. Pingback: mangalib
  147. Pingback: x
  148. Pingback: 9xflix
  149. Pingback: xnxx
  150. Pingback: 123movies
  151. Pingback: pharmacy canada
  152. Pingback: canadian pharmacys

Comments are closed.