Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# VB未实现集合_C#_Asp.net_.net_Vb.net_Linq - Fatal编程技术网

C# VB未实现集合

C# VB未实现集合,c#,asp.net,.net,vb.net,linq,C#,Asp.net,.net,Vb.net,Linq,我在VB ASP.Net项目中使用linq来填充搜索结果。使用intersect比较作为查询的单词列表和字符串。我在一个空格上拆分字符串,以确保两个集合相交。但是VB没有意识到这一点,并抛出以下错误 An exception of type 'System.MissingMemberException' occurred in Microsoft.VisualBasic.dll but was not handled in user code Additional information: P

我在VB ASP.Net项目中使用linq来填充搜索结果。使用intersect比较作为查询的单词列表和字符串。我在一个空格上拆分字符串,以确保两个集合相交。但是VB没有意识到这一点,并抛出以下错误

An exception of type 'System.MissingMemberException' occurred in Microsoft.VisualBasic.dll but was not handled in user code

Additional information: Public member 'Count' on type 'String' not found.
select语句中出现的代码如下

MatchCount = keywords.Intersect(IIf(IsNothing(t.TripName), t.tbl_Subject.SubjectName & " in " & t.tbl_City.CityName, t.TripName).ToLower().Split(" ")).Count() / IIf(IsNothing(t.TripName), t.tbl_Subject.SubjectName & " in " & t.tbl_City.CityName, t.TripName).Count
为它的难读性道歉,它在select语句中,因此必须是一个查询。跨多行拆分帐户它将如下所示:

Dim name as string = IIf(IsNothing(t.TripName), t.tbl_Subject.SubjectName & " in " & t.tbl_City.CityName, t.TripName)
MatchCount = keywords.Intersect(name.ToLower().Split(" ")).Count()
编辑:-完整、原始(不是我写的)select语句

toReturn.AddRange(results.Select(Function(t) New SearchResult() _
                      With {
                            .MatchCount = keywords.Intersect(If(IsNothing(t.TripName), t.tbl_Subject.SubjectName & " in " & t.tbl_City.CityName, t.TripName).ToLower().Split(" ")).Count() / If(IsNothing(t.TripName), t.tbl_Subject.SubjectName & " in " & t.tbl_City.CityName, t.TripName).Count, _
                            .UID = t.TripID, _
                            .Title = IIf(t.TripName Is Nothing, t.tbl_Subject.SubjectName & " in " & t.tbl_City.CityName, t.TripName), _
                            .Description = t.DescriptionLong.ToString().Replace("<p>", "").Replace("</p>", "").Replace("<b>", "").Replace("</b>", "").Replace("<strong>", "").Replace("</strong>", "").Replace("<i>", "").Replace("</i>", "").Replace("<em>", "").Replace("</em>", "").Replace("<br>", "").Replace("<br />", ""), _
                            .ImageURL = IIf(t.ImageSub04 Is Nothing, t.tbl_City.ImageThumb, t.ImageSub04),
                            .URL = "/" & t.tbl_Subject.SubjectWebName & "/" & t.tbl_Country.CountryWebName & "/" & _
                                        IIf(t.TripWebName Is Nothing, _
                                        t.tbl_City.CityWebName, _
                                        t.TripWebName) _
                                        & "_trip/",
                            .IsCity = keywords.Contains(t.tbl_City.CityName) Or keywords.Contains(t.tbl_Country.CountryName)
                         }).OrderBy(Function(sr) sr.IsCity).ThenByDescending(Function(sr) sr.MatchCount))
toReturn.AddRange(results.Select(函数(t)newsearchresult())_
与{
.MatchCount=关键字.Intersect(如果(在“&t.tbl\U City.CityName,t.TripName,t.ToLower().Split(“”)).Count()/If(没有(t.TripName),t.tbl\U Subject.SubjectName&“在”&t.tbl\U City.CityName,t.TripName中”)。计数_
.UID=t.TripID_
.Title=IIf(t.TripName为空,t.tbl_Subject.SubjectName&“in”&t.tbl_City.CityName,t.TripName)_
.Description=t.DescriptionLong.ToString().Replace(“”,”).Replace(“”,”).Replace(“,”).Replace(“”,”).Replace(“”,”).Replace(“,”).Replace(“,”).Replace(“,”).Replace(“,”,”).Replace(“
,”)_ .ImageURL=IIf(t.ImageSub04为空,t.tbl_City.ImageThumb,t.ImageSub04), .URL=“/”&t.tbl\u Subject.SubjectWebName&“/”&t.tbl\u Country.CountryWebName&“/”&_ IIf(t.TripWebName什么都不是_ t、 tbl_City.CityWebName_ t、 TripWebName)_ &“_trip/”, .IsCity=keywords.Contains(t.tbl\u City.CityName)或keywords.Contains(t.tbl\u Country.CountryName) }).OrderBy(函数(sr)sr.IsCity)。然后按降序(函数(sr)sr.MatchCount))
既然在字符串上也使用了
Count()
,为什么不在那里使用
Length

因为,正如我在问题中所说,这是一个精选语句,所以我不能 存储变量

您甚至可以在查询中使用匿名类型,或者(在查询语法中)使用
Let
关键字

在这种情况下,我想这就是你想要做的,看看它的可读性有多高:

Dim sResults = From res In results
               Let longTripName = String.Format("{0} in {1}", res.tbl_Subject.SubjectName, res.TripName)
               Let trip = If(res.TripName, longTripName)
               Let tripWords = trip.ToLower().Split(" "c)
               Let matching = keywords.Intersect(tripWords).Count()
               Let matchCount = matching / trip.Length
               Let title = " this is your task "
               Let description = " this is your task "
               Let imageURL = " this is your task "
               Let url = " this is your task "
               Let isCity = True ' also your task '
               Select sr = New SearchResult With {
                   .MatchCount = matchCount,
                   .Title = title,
                   .Description = description,
                   .ImageURL = imageURL,
                   .URL = url,
                   .IsCity = isCity
               }
               Order By sr.IsCity, sr.MatchCount Descending
toReturn.AddRange(sResults)
但总的来说,我建议在
SearchResult
中实现一个适当的方法或构造函数,它封装了逻辑和复杂性


另外,由于您使用的是
Split(“”)
,并且可以编译,因此您应该真正更改为
选项Strict On
。我猜你会遇到很多编译器错误,这是一件好事,因为它向你展示了你必须修复的东西。这里您必须使用
Split(“'c)

字符串具有
长度
,而不是
计数
属性。无论出于何种原因,
keywords.Intersect
的结果都是一个字符串。
关键字的类型是什么
相交的定义是什么?您使用的是
可枚举.Intersect
还是您自己的版本?为什么不使用多行和变量来存储值?这将更具可读性。也许您可以将代码抽象到相关问题,而无需使用thos
IIF
s(您知道有一个
If
-运算符?)。Enumerable.Intersect,关键字是字符串列表。因此,返回的类型应始终为enumerableSwitch Option Strict On,并将
IIf
更改为
If
以开始。修复那里抛出的任何错误可能会修复您的总体错误problem@TimSchmelter+1-刚刚意识到有另一个调用
Count()
再次隐藏在其中,这没有帮助。因为我的代码最初在select语句中。我把整个陈述加在后面question@LiamHT例如再看一看。在VB.NET中,您应该从更强大、更可读的查询语法中获益。@LiamHT没有任何东西阻止您在select语句中调用函数。只需将整个块提取到一个单独的函数,该函数接受
t
是什么,并返回
SearchResult
,然后在Select的参数上调用它。LINQ甚至允许您将其称为
results。选择(MyFactoryMethod)
,因为参数和结果是推断出来的。