Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VS2008 intellisense hiding an extension method.

1 view
Skip to first unread message

Frank Rizzo

unread,
May 14, 2008, 4:38:55 PM5/14/08
to
How come VS2008 does not show built-in extension methods for the string
class? Like ToList() method, for instance.


Jon Skeet [C# MVP]

unread,
May 14, 2008, 5:49:17 PM5/14/08
to
Frank Rizzo <no...@none.net> wrote:
> How come VS2008 does not show built-in extension methods for the string
> class? Like ToList() method, for instance.

Have you got a using directive for System.Linq?

--
Jon Skeet - <sk...@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com

Frank Rizzo

unread,
May 14, 2008, 6:22:10 PM5/14/08
to
Jon Skeet [C# MVP] wrote:
> Frank Rizzo <no...@none.net> wrote:
>> How come VS2008 does not show built-in extension methods for the string
>> class? Like ToList() method, for instance.
>
> Have you got a using directive for System.Linq?

Yep.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = "123,323,4,111";
List<char> lst = s.ToList();
}
}
}

Chris Dunaway

unread,
May 15, 2008, 10:44:49 AM5/15/08
to
On May 14, 5:22 pm, Frank Rizzo <n...@none.net> wrote:
> Jon Skeet [C# MVP] wrote:
>

I can confirm the issue.

Is it because ToList is not an extension method for type string but of
IEnumerable<T>? That's the only reason I can think of.

Chris

Marc Gravell

unread,
May 15, 2008, 11:02:42 AM5/15/08
to
My assumption is that they hard-coded the IDE to skip it to avoid
confusion... not many people thing of strings as enumerable objects...

But the compiler will accept it - and IMO it makes things clearer.

Marc

Frank Rizzo

unread,
May 15, 2008, 1:12:43 PM5/15/08
to

Anyone willing to install the SP1 beta and try it?

Jon Skeet [C# MVP]

unread,
May 15, 2008, 5:31:57 PM5/15/08
to
Frank Rizzo <no...@none.net> wrote:
> Marc Gravell wrote:
> > My assumption is that they hard-coded the IDE to skip it to avoid
> > confusion... not many people thing of strings as enumerable objects...
> >
> > But the compiler will accept it - and IMO it makes things clearer.
>
> Anyone willing to install the SP1 beta and try it?

I'd expect it to behave the same way - it sounds unlikely that it's a
bug, and much more likely that it's a feature as Marc suggests. It's
quite rare that you actually want to treat a string as an
IEnumerable<char> in my experience.

Marc Gravell

unread,
May 16, 2008, 3:37:18 AM5/16/08
to
>> Anyone willing to install the SP1 beta and try it?

It is identical on SP1 beta.

Which by the way is really, really good (IMO). The IDE feels much more
responsive; warnings / errors appear immeditely, for example.

Marc

José Joye

unread,
May 16, 2008, 1:31:33 PM5/16/08
to
I guess you are right.

I'm currently reading "LINQ in Action".
In chapter 4.2.1, it is stated that:
"The extension methods for the System.String are specifically excluded [from
intelliSense] because it is seen as highly unusual to treat a string object
as an IEnumerable<char>."

- José

"Jon Skeet [C# MVP]" <sk...@pobox.com> a écrit dans le message de
news:MPG.2296bc2...@msnews.microsoft.com...

0 new messages