转换操作的优先级在C# [英] Cast operation precedence in C#
本文介绍了转换操作的优先级在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将在C#下面的差异此事显著
Will the differences below matter significantly in C#?
int a, b;
double result;
result = (double)a / b;
result = a / (double)b;
result = (double)a / (double)b;
你使用哪一种?
Which one do you use?
推荐答案
在分立前发生的演员。
在你的例子,它不会不管你做哪一个,如果一个操作数是一家双,运行时会投/其他转换为双以及
In your examples, it doesn't matter which one you do as if one operand is a double, the runtime will cast/convert the other to a double as well.
这看起来像一个微型优化 - 不是值得担心或处理,除非测量结果表明它确实是一个瓶颈。
This looks like a micro-optimization - not something worth worrying about or dealing with unless measurements show it is indeed a bottleneck.
这篇关于转换操作的优先级在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文