使用“表达式主体功能和属性"的好处是什么? [英] What is the benefit of using "Expression Bodied Functions and Properties"

查看:49
本文介绍了使用“表达式主体功能和属性"的好处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实看到许多人使用该新功能,但是使用这些表达式有什么好处?

示例:

 公共替代字符串ToString()=>string.Format("{0},{1}",第一,第二);公共字符串Text =>string.Format("{0}:{1}-{2}({3})",时间戳,进程,配置,用户); 

此问题与不同之所以如此,是因为我不仅要问性能和效率是否会发生变化,还要问编译后的代码(IL代码)的不同之处,以及它是否是最佳实践,应该在现实世界中使用./p>

这个问题也不是不是 主题不重要,因为我要求的是现实生活中的企业经验,而不是建议.因此,不推荐使用,而是解释为什么您会使用该功能或​​为什么不使用该功能以及使用该功能有什么经验!

解决方案

它提供了更好的可读性并节省了代码空间.更好.

I do have seen many using that new feature, but what is the benefit of using those expressions?

Examples:

public override string ToString() => string.Format("{0}, {1}", First, Second);

public string Text =>
string.Format("{0}: {1} - {2} ({3})", TimeStamp, Process, Config, User);

This question is different to this one, because I am not only asking if the performance and efficiency does change, but also about the difference of the compiled code (IL code) and if it is best practice and should be used in the real world.

This question is also not off topic, because I am asking for real life enterprise experience and not recommendations. Therefore don't recommend, but explain why you would or why you would not use that feature and what experiences you have with it!

解决方案

It provides better readability and saves some space in your code. It is just nicer.

这篇关于使用“表达式主体功能和属性"的好处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆