Question: How is it possible to find a specific object from a list?
Lets say i have a function that takes an object and a list that contains objects of this type and returns the number at which position the specific object is found. 

The only way i could think of a solution is to run the list through with a foreach loop, but isn't there a better way?

Thanks

Answer: 
You can use the `IndexOf(T item)` method:

```
myList.IndexOf(myItem);

```

It returns the index of the first occurrence of the item.
To see whether object is there You might just need `List<T>.Contains` [method](https://msdn.microsoft.com/en-us/library/bhkz42b3%28v=vs.110%29.aspx)

It states, 

> 
> Determines whether an element is in the List.
> 
> 
> 

And you need to use it like `List<T>.Contains(T type item)` , where `T` is the same type of `List` and `item` you need to compare. In your case it's a the type of `Object`

And to return the index you can use `List<T>.IndexOf` [Method](https://msdn.microsoft.com/en-us/library/e4w08k17(v=vs.110).aspx)

> 
> Searches for the specified object and returns the zero-based index of the first occurrence within the entire List.
> 
> 
> 

Simple Console program 

```
class Program
    {
        static void Main(string[] args)
        {
            MyType a = new MyType() { id = 10 };
            MyType b = new MyType() { id = 20 };
            MyType c = new MyType() { id = 30 };

            List<MyType> testList = new List<MyType>();

            testList.Add(a);
            testList.Add(b);

            Console.WriteLine(testList.Contains(a)); // <= Will return true
            Console.WriteLine(testList.Contains(c)); // <= Will return false

            Console.WriteLine(testList.IndexOf(a)); // <= will return 0 : the index of object a

            Console.ReadKey();    
        }   
    }

    // A simple class
    class MyType
    {
        private int ID;

        public int id
        {
            get { return ID; }
            set { ID = value; }
        }
     }

```