I see language features like C#’s foreach loop (which requires the use of IEnumerable), and its using syntax (which uses IDisposable, knowing which method to call), and LINQ (which I assume uses a heap of .NET stuff too). All of this seems very tied-in to the .NET framework. So:
- Could C# exist with a different framework? (Does it already?)
- If so, how does a language specify “foreach loops require an IEnumerable instance” without tying it in to a framework.
The best place to investigate this is the C# language specification.
For example, in the case of enumerables, here are some snippets from the spec:
This ties in nicely with how these interfaces are actually defined in the .NET BCL, although it would be completely possible for a different (i.e. non-.NET) framework to provide a similar, compatible implementation that a C# compiler could then target.
Portions of the spec that are hard to separate from the .NET framework are normally marked with:
On another note,
foreachdoesn’t actually requireIEnumerable; it can use a sort of ‘duck-typing’, which you can read about in section 8.8.4 of the spec.