搜索整数数组
我收到一个字符串,如下所示:
'202,203,204,205,226,230,274'
我想将此字符串分解为一个数字数组,并返回具有这些 Id 的所有记录。
到目前为止,我有:
string[] myArray = myString.Split(',');
int[] myIntArray = new int[myArray.Length];
for(int x = 0; x < myArray.Length; x++) {
myIntArray[x] = Convert.ToInt32(myArray[x].ToString());
}
model.Records = db.Records
.Where(q => q.RecordId.Contains(myIntArray)
.ToList();
它抱怨 Contains 不能与整数一起使用。我是否对 Contains 的实际用途感到困惑?
提前致谢!
I've got a string coming in like so:
'202,203,204,205,226,230,274'
I want to break this string down into an array of numbers and get back all the records with those Ids.
So far, I have:
string[] myArray = myString.Split(',');
int[] myIntArray = new int[myArray.Length];
for(int x = 0; x < myArray.Length; x++) {
myIntArray[x] = Convert.ToInt32(myArray[x].ToString());
}
model.Records = db.Records
.Where(q => q.RecordId.Contains(myIntArray)
.ToList();
It's complaining about Contains not working with ints. Am I get confused as to what Contains actually does?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你想要这样做:
按照你的方式,你期望
RecordId
是一个数组(我假设它是一个int
?),而我认为您想要获取单个RecordId
并查看它是否在int
数组中。I think you want to do:
The way you have it, you're expecting the
RecordId
to be an array (I'm assuming it's anint
?), whereas I think you want to take the singleRecordId
and see if it is in the array ofint
s.