从c#6开始,只读属性可简写为表达式属性。它使用双箭头替换了花括号,get访问器和return关键字。 例如:
decimal currentprice,sharedowned; public decimal worth { get{ return currentprice*sharedowned; } }
使用表达式属性如下:
public decimal worth=>currentprice*sharedowned;
c#7进一步允许在set访问器上使用表达式体,其书写方法如下:
public decimal worth { get=>currentprice*sharedowned; set=>sharedowned=value }
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论