0

I have this class I'm using to create a list of values

public class map
{
    private static List<map> mapValues = new List<map>();
    public static IEnumerable<map> AllInstances
    {
        get { return mapValues; }
    }

    public int Row { get; set; }
    public int Column { get; set; }
    public Object theobject { get; set; }

    private map()   // Private ctor ensures only a member
    {               // function can create a new map
    }
    public static map Create()
    {
        var mv = new map();
        mapValues.Add(mv);
        return mv;
    }

    public static void Delete(map itemToRemove)
    {
        mapValues.Remove(itemToRemove);
    }
}

I have based this class from this comment

But when I come to the part of var Foundit = MyData.AllInstances.FirstOrDefault(md => md.Device == "blah"); Myclass does not have this FirstOrDefault.

The idea with this list is to have a grid/map-like system for placing objects in a WPF canvas.

What am I missing to get this working?

Community
  • 1
  • 1
  • 2
    `FirstOrDefault()` is an [`IEnumerable` extension](https://msdn.microsoft.com/library/bb340482%28v=vs.100%29.aspx). You need to import the `System.Linq` namespace. – mshsayem Dec 02 '15 at 11:02

2 Answers2

1

FirstOrDefault is an extension method, so try adding this namespace:

using System.Linq;

Another point: As far as the AllInstances is a static class member, you do not have to call it from a map instance like MyData, simply you can call it from the class like this:

map.AllInstances  //access AllInstances through the class name
Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
0

Add using System.Linq; at the top of the file where you want to use .FirstOrDefault(...).

Maarten
  • 22,527
  • 3
  • 47
  • 68