VS2008 intellisense hiding an extension method.

  • Thread starter Thread starter Frank Rizzo
  • Start date Start date
F

Frank Rizzo

How come VS2008 does not show built-in extension methods for the string
class? Like ToList() method, for instance.
 
Frank Rizzo said:
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 said:
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();
}
}
}
 
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();
}
}

}

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
 
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
 
Marc said:
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?
 
Frank Rizzo said:
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.
 
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
 
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é
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top