Hello. It is required to include source code from the MoreLinq project into the Visual Studion 2015 Community project. I tried to run sulution and compile the projects, but the projects were not even loaded, the following error occurs:

C: \ Users \ rostov.d \ Desktop \ MoreLINQ-master \ MoreLinq \ MoreLinq.csproj: error: The default XML namespace for this project should be MSBuild XML namespace. If the project was created in MSBuild 2003 format, add xmlns = "http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project was created in the old format 1.0 or 1.2, convert it to MSBuild 2003 format. C: \ Users \ rostov.d \ Desktop \ MoreLINQ-master \ MoreLinq \ MoreLinq.csproj

I tried to copy only the necessary source code files into my project and compile. But Visual Studio swears at the construction of this type:

return _(); IEnumerable<T> _() 

I suspect that this is due to the delayed execution of Linq queries. I could not find documentation on the Internet. What is this "return"_(); and how to compile such code under the Visual Stuio 2015 Community? An example of a function with this return:

 public static IEnumerable<T> Exclude<T>(this IEnumerable<T> sequence, int startIndex, int count) { if (sequence == null) throw new ArgumentNullException(nameof(sequence)); if (startIndex < 0) throw new ArgumentOutOfRangeException(nameof(startIndex)); if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); return _(); IEnumerable<T> _() { var index = -1; var endIndex = startIndex + count; using (var iter = sequence.GetEnumerator()) { // yield the first part of the sequence while (iter.MoveNext() && ++index < startIndex) yield return iter.Current; // skip the next part (up to count items) while (++index < endIndex && iter.MoveNext()) continue; // yield the remainder of the sequence while (iter.MoveNext()) yield return iter.Current; } } } 
  • Oh, cool, new features. On the contrary, this thing is newer than VS2015. And used original. It seems to be possible to put some nuget-package to support the new Sharp. - Qwertiy
  • nuget probably need to be installed - Anatol
  • In fact, this is just a nested method, just the formatting floated) And yes, I need C # 7, and accordingly VS2017 - Andrey NOP
  • @ Andrei, C # 7 can somehow be compiled in VS2015 ... - Qwertiy
  • one
    @ AGS17, not a duplicate, because the version of Sharp is not the same. - Qwertiy

1 answer 1

Here is the declaration of the nested method:

 IEnumerable<T> _() 

This is just a method with no parameters, which is named _ and returns an IEnumerable<T> .

 return _(); 

And here the result of calling this method is returned.

Because of the use of the yield return method, it will not start executing before the first element of the return sequence is accessed. However, the author wanted the input validation section

 if (sequence == null) throw new ArgumentNullException(nameof(sequence)); if (startIndex < 0) throw new ArgumentOutOfRangeException(nameof(startIndex)); if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); 

executed immediately; it must be in a method that does not contain a yield return . T. o. the whole method falls into two.

And some links:

  • Add a reference where to read about it in more detail? - Anatol
  • one
    @Anatol, I added about iterators, but I ’m looking for new features ... - Qwertiy
  • one
    @Anatol, added more. - Qwertiy