Some time ago I was working on a rather twisted project - I could write code in only one area, and later it will be added to the C # function (by another module).
I could only use namespaces that were previously declared (I did not affect them) and I could only use variables from the scope in which I worked. Because of this, I was unable to change the headers and libraries.
The problem arose when I wanted to use shared collections - I could not use either lambda expressions or LINQ - I just was not able to deliver using System.Linq; since I did not have access to the file header.
I only had to do a simple thing, and without LINQ or lambda it was easy to manage. However, after that I was wondering what would happen if I had to use some more complex operations on IEnumerable. This begs my question:
Is it possible to use LINQ or lambdas without changing the file header and adding new namespaces?
Say a List<int> _Numbers = new List<int>(); . Let it be filled with some numbers. Now I want to select all even numbers from it.
With using System.Linq; in the title, the solution is obvious:
List<int> _NewList = _Numbers.Where(n => n % 2 == 0).ToList();
or
List<int> _NewList = (from _Number in _Numbers where _Number % 2 == 0 select _Number).ToList();
But without including LINQ, how can I achieve this? My first guess would be something like:
List<int> _NewList = System.Linq.
I know that the problem is quite exotic, and this is very unusual for this, but I'm just curious, and I did not find information about this case.