KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
One of the extension methods on IEnumerable<T> is .AsEnumerable() . This method converts the enumerable object it was called on into an instance of IEnumerable<T> . However, since an object must implement IEnumerable<T> in order to apply to this extension method, converting to IEnumerable<T> is a simple matter of casting to IEnumerable<T> . My question is why does this method exist at all? Example: List<string> strings = new List<string>() { "test", "test2", "test3" }; IEnumerable<string> stringsEnum1 = strings.AsEnumerable(); IEnumerable<string> stringsEnum2 = (IEnumerable<string>)strings; In the example above, stringsEnum1 and stringsEnum2 are equivalent. What's the point of the extension method? As a corollary, why is there an .AsQueryable() method when casting to IQueryable<T> is equivalent?
Tags (comma-separated)
Save Edits
Cancel