C#中if-else的简写
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/241
?号后面是判断之后的输出语句,
:的左边是判断为真的时候的输出
右边是判断为否的时候的输出
举个例子:
m_GroundCheckDistance = m_Rigidbody.velocity.y < 0 ? m_OrigGroundCheckDistance : 0.01f;
相当于:
if(m_Rigidbody.velocity.y < 0)
{
m_GroundCheckDistance = m_OrigGroundCheckDistance;
}
else
{
m_GroundCheckDistance =0.01f;
}
应用场景:
当只有1个需要判定的值的时候。
This article was last edited at 2020-04-07 16:34:21