LINQ intellisense stopped working
What happend to my Intellisense??
When I type a line like this ...
Dim users = (From u In Membership.GetAllUsers Select u.UserName)
... I get (almost) no Intellisense when I get to the Select u.
part. Only Equals, GetHashCode, GetType, ReferenceEquals and ToString appears. Not "UserName" and the other relevant propeties of the MembershipUser class.
Any suggestions?
I tried devenv.exe 开发者_运维百科/ResetSettings
from the VS Command prompt as suggested in this question, but it didn't help.
The reason why this is happening is because the return type of MemberShip.GetAllUsers
is MembershipUserCollection
. This collection type only implements IEnumerable
and is not strongly type. The compiler can only infer the type of the elements in the collection is Object
. Hence you get intellisense for Object
in the select clause.
You need to tell the compiler more information about the type of the elements. For instance if you know all of the values are MembershipUser
instances you could use the Cast function to tell the compiler
From u in Membership.GetAllUsers().Cast(Of MembershipUser) ...
What JaredPar told you is true , because that collection is not IEnumerable
so you have to tell the compiler which object type inside your collection
And if that still not working be sure that you imported the linq namespace in the top of the class
Import System.Linq
:)
精彩评论