0

I'm sure this is something simple, but I am apparently having a "senior moment". Why in the following code is linq unavailable to the base class.

    public class Strings: List<String> {
    public Strings() { }

    public Strings(IList<String> strings) : base(strings) { }

    public Strings Skip2(int i) {
        var x = new List<String>();
        var y = x.Skip(1).ToList();
        var z = this.Skip(1).ToList();
        return new Strings(base.Skip(i).ToList());
        }
    }

This code produces a "Error CS0117 'List<string>' does not contain a definition for 'Skip'" error for "base.Skip(i)" (no error for x.Skip or this.Skip). Why are the linq extension methods unavailable using the base keyword. I'm running c# v6 in vs2015 if it matters.

Dweeberly
  • 4,668
  • 2
  • 22
  • 41
  • 3
    `base` is pretty limited. You cannot call extension methods on `base`. – CodeCaster Jan 03 '16 at 20:17
  • Do you have `using System.Linq;` at the top of the code file? – Emond Jan 03 '16 at 20:18
  • @ErnodeWeerd Yes that is why x.Skip and this.Skip have no errors. – Dweeberly Jan 03 '16 at 20:19
  • @CodeCaster Thanks, is that info buried in the standard somewhere, it didn't show up on searches. Seems like an odd restriction. – Dweeberly Jan 03 '16 at 20:21
  • 1
    It is not really buried: [_"The base keyword is used to **access members of the base class** from within a derived class"_](https://msdn.microsoft.com/en-us/library/hfw7t1ce.aspx). Extension methods are not members of the base class. :) – CodeCaster Jan 03 '16 at 20:23

0 Answers0