请帮帮我。我被困在我的阵列盒子里。我是新手。特别是要获得超过2个变量的数组。我已经浏览了谷歌,但我没有得到我想要的东西,现在我已经被卡住了:(
我有这样的数组
foreach (var receive_ in receive)
{
foreach (var display_ in display)
{
if (receive_ == display_)
{
//do something
}
}
}
首先,我从接收和显示中得到了相同的值
foreach (var receive_ in receive)
{
foreach (var display_ in display)
{
if (receive_ == display_)
{
string[] ccTemp = cc.Split(new char[] { ',' });
for (int i = 0; i < receive.Length; i++)
{
if (receive[i] == "1")
{
if (_ccIsReceiveAndDisplay.Trim() != "") _ccIsReceiveAndDisplay += ",";
_ccIsReceiveAndDisplay += ccTemp[i];
}
else
{
if (_ccIsReceiveAndDisplay.Trim() != "") _ccIsReceiveAndDisplay += ",";
_ccIsReceiveAndDisplay += ccTemp[i];
}
}
}
}
}
然后我的问题是,如何获得a@gmail.com,c @ gmail.com? 我试过这个
var returnPromise = myService.method()
returnPromise.done(() => {
mock.verify()
})
但它只会得到= 1的值。没有收到1并且显示= 1
答案 0 :(得分:0)
如果所有数组的长度相同,请使用for
和索引。
像这样:
for (var index=0; index<receive.length; index++)
if (receive[index] == "1" && display[index] == "1")
DoSomethingWithEmail( ccTemp[index] )
这也更快,因为它只在数组中循环一次,而不是在数组中每个元素循环一次。
作为奖励,请通过linq-way获取电子邮件:
receive.Zip(display, (a,b) => new {A=a, B=b}).Zip(ccTemp, (ab,c) => new {use=ab.A=="1"&&ab.B=="1", email=c}).Where( x=> x.use ).Select( x => x.email)