By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,201 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,201 IT Pros & Developers. It's quick & easy.

VS2008 intellisense hiding an extension method.

P: n/a
How come VS2008 does not show built-in extension methods for the string
class? Like ToList() method, for instance.
Jun 27 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Frank Rizzo <no**@none.netwrote:
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
Jun 27 '08 #2

P: n/a
Jon Skeet [C# MVP] wrote:
Frank Rizzo <no**@none.netwrote:
>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<charlst = s.ToList();
}
}
}
Jun 27 '08 #3

P: n/a
On May 14, 5:22 pm, Frank Rizzo <n...@none.netwrote:
Jon Skeet [C# MVP] wrote:
Frank Rizzo <n...@none.netwrote:
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<charlst = s.ToList();
}
}

}
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
Jun 27 '08 #4

P: n/a
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
Jun 27 '08 #5

P: n/a
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.

Marc
Anyone willing to install the SP1 beta and try it?
Jun 27 '08 #6

P: n/a
Frank Rizzo <no**@none.netwrote:
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<charin my experience.

--
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
Jun 27 '08 #7

P: n/a
>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
Jun 27 '08 #8

P: n/a
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.coma écrit dans le message de
news:MP*********************@msnews.microsoft.com. ..
Frank Rizzo <no**@none.netwrote:
>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<charin my experience.

--
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
Jun 27 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.