0

I am writing a Windows 8.1 Universal app. In the shared project, I have an object of List class and want to access the ElementAt() extension method.

But the method is not showing up in the Visual Studio 2013's suggestions. If I ignore this and enter it myself, the red squiggly lines showing error appear below ElementAt and the project doesn't build. Can anyone help?

AvinashK
  • 3,309
  • 8
  • 43
  • 94

2 Answers2

3

If you want to use Linq Extension methods make sure you include the System.Linq namespace.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • If you have System.Linq imported or VS is not giving you the suggestion to import System.Linq you probably forgot to use await on an async method that returns Task> as you were assigning to a dynamic var? var myList = _myAsyncMethod(); Should be var myList = await _myAsyncMethod(); – Sean Anderson Jan 18 '19 at 23:47
2

Add using System.Linq. What you are trying to use is what is known as an extension method and that is located in a differnt namespace as it is not actually a method on the List object itself.

You have linked the documentation yourself. Have a look at then namespaces and you will see where you have gone wrong.

David Pilkington
  • 13,528
  • 3
  • 41
  • 73