2015-12-18 30 views
1

如果在第一个数组中找不到第二个数组中的所有值,则需要删除它们中的所有值。但是,我在C#中找不到在线命令。尽管我已经为其他语言找到了它。如果在MVC中的第二个数组中找不到,则从第一个数组中删除

这是我的第一个数组:

string[] EmailList = (from user in db.Users join subscribor in Subscribors on user.UserId equals subscribor orderby user.FirstName select user.EmailAddress).ToArray(); 

和我的第二个数组:

string[] TechList = (from user in db.Users join tech in techs on user.UserId equals tech select user.EmailAddress).ToArray(); 

,这是我试过的代码:

EmailList = EmailList.Intersect(TechList); 

我也尝试了几个相交的其他变体,但没有任何作用。在这行代码我收到以下错误:

cannot emplicitly converty type 'system.collections.generic.IEnumerable to string[]

回答

1

EmailList.Intersect(TechList)不返回string[];它会返回一个System.Collections.Generic.IEnumerable,就像它告诉你的一样。尝试添加.ToArray(),像这样:

EmailList = EmailList.Intersect(TechList).ToArray(); 
3

您的代码

EmailList = EmailList.Intersect(TechList); 

否则罚款,但相交返回IEnumerable的,和你的emailList字符串类型的[]。您可以像这样将IEnumerable转换为字符串[]

EmailList = EmailList.Intersect(TechList).ToArray(); 
相关问题