An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
You could wrap your SelectManyEx3 definition inside a class Program { ... } definition and avoid using top-level statements, but if you do want to use them then the compiler makes the assumption that the code that you want to be put inside the generated class entry point (even with top-level statements there's always an entry class, you just don't see it) will be at the top of the file and all class definitions are after them, or in separate compilation units.