Struggling with one thing about interfaces.

So, I watching a tutorial about IEnumerable and I realized I don't really understand how interfaces work.

What I thought they were: Similar to classes as a level of abstraction, but they normally don't have any default method and instead just have all the methods that NEED to be implemented by their child classes instead.
They also can't be instantiated as objects (but objects of classes that implement them can)

However, I ran into an example close to this:

EXAMPLE:

List<MyClass> MyList = new List<MyClass> {...};

ImyInterface<MyClass> ModifiedList = MyList

(Suppose that ImyInterface is an interface and that MyClass is a class that implements ImyInterface)

Here, the interface name (alongside with the generic indicator <>) is put right before an object named ModifiedList. Which made me think that ModifiedList was an object of the class ImyInterface...

What I don't understand is:

First: That interfaces in theory were supposed to not have objects instantiated directly from them

Second: Even if they could, what is the point of doing this instead of directly using MyList, if MyClass already implements all the ImyInterface methods...

When I asked chat gpt (yeah, Im THAT desperate), it told me that actually ModifiedList is an variable of type ImyInterface, which is possible because variables are not the same as objects, and interfaces can't be objects but they can be variables. Now, I'm not sure if chat gpt is bullshitting me, so I was left unsure, since I was taught that variables were a simplified term, but are actually objects internally too. Which is why I was doubting the AI explanation.

So, regarding the 2 questions I made above, what is the correct explanation?
Sorry for the wall of text, I'm really confused.
Was this page helpful?