Won't compile: using IEnumerable<T> = System.Collections.Generic.IEnumerable<T>;

D

Doug Dew

This won't compile:

using IEnumerable<T> = System.Collections.Generic.IEnumerable<T>;

namespace MyNamespace
{
public class MyClass<T> : IEnumerable<T>
{
// Appropriate stuff here
}
}

Is this by design? In other words, when using the classes and
interfaces of the System.Collections.Generic namespace, must I make an
exception to my normal coding style and change the above code to read:

using System.Collections.Generic;

namespace MyNamespace
{
public class MyClass<T> : IEnumerable<T>
{
// Appropriate stuff here
}
}

If so, then I'm kind of bummed. To make it easier for others to read
my code, I like to create using aliases for each type that I use
within a file, and to arrange the aliases alphabetically. Although
this practice seems anal, years of Java coding and reading others'
Java code made it clear to me that explicitly identifying the
namespaces (packages) of types makes it much easier for a reader to
figure out where a type is "coming from" whenever the reader
encounters a usage of a type within a file.

Thank you in advance.
 
M

Morten Wennevik

Hi Doug,

What is the System.Collections.Generic ???

try

using IEnumerable = System.Collections.IEnumerable;

and it will compile fine :)

What does the <T> mean?
 
M

Mattias Sjögren

M

Morten Wennevik

Ah, I wish people would stop using this group for beta questions, or at least specify v2.0 or whidbey in their questions :(
 
P

Peter Sestoft

This won't compile:

using IEnumerable<T> = System.Collections.Generic.IEnumerable<T>;

namespace MyNamespace
{
public class MyClass<T> : IEnumerable<T>
{
// Appropriate stuff here
}
}

A workable approach is to abbreviate the namespace:

using SCG = System.Collections.Generic;

namespace MyNamespace
{
public class MyClass<T> : SCG.IEnumerable<T>
{
// Appropriate stuff here
}
}

Peter
 

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

Top