Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

c# - Why doesn't VS 2008 display extension methods in Intellisense for String class

Since String implements IEnumerable<char>, I was expecting to see the Enumerable extension methods in Intellisense, for example, when typing the period in

String s = "asdf";
s.

I was expecting to see .Select<char>(...), .ToList<char>(), etc. I was then suprised to see that the extension methods do in fact work on the string class, they just don't show up in Intellisense. Does anyone know why this is? This may be related to this question.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's by explicit design. The problem is that while String most definitely implements IEnumerable<T>, most people don't think of it, or more importantly use it, in that way.

String has a fairly small number of methods. Initially we did not filter extension methods off of String and the result was a lot of negative feedback. It almost tripled the number of methods at times with the right imports. With all of the extension methods displayed, people often couldn't see the String method they were looking for in the noise.

String is a ... simple type and it's better to view it that way :)

It's still completely possible to call an extension method on string. It's just likely not going to show up in intellisense.

EDIT: String actually has quite a few methods. But because many of them are overloads they collapse in intellisense.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...