一次多个相等运算符 [英] Multiple equality operators at once

查看:95
本文介绍了一次多个相等运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但是如何一次比较多个变量?

假设我有3个变量:a,b和c,我需要检查它们是否都相同.当然,a==b && b==c可以工作,但是是否有像a==b==c这样的较短语法(这不起作用)?

This might be a stupid question, but how do I compare multiple variables at once?

Say I have 3 varaibles: a, b and c, and I need to check whether they are all the same. Of course, a==b && b==c works, but is there a shorter syntax like a==b==c (this doesn''t work)?

推荐答案

您可以创建一个函数来接受变量列表并将它们全部与另一个项目进行比较(您可以使用for循环).您将使用如下所示的内容:
You could create a function that takes a list of variables and compares them all to another item (you''d use a for loop). You would use it something like this:
var matchesAll = EqualsAll(b, [a, c, d, e, f, g]);


如果您有很多变量,那只会减少输入的数量.


That only cuts down on how much you have to type if you have a lot of variables though.


没有简短的语法,这就是您得到的全部内容.
No shorter syntax, that is all you get.


尝试...

if (a-a)=(b-c)
try...

if (a-a)=(b-c)


这篇关于一次多个相等运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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