How to get type T from an instance of a generic class or method in C#?
Hello everyone! I'm new to C# and I'm having a problem with generic types. Let's say I have a generic class:
```csharp
public class MyList
{
private List items = new List();
public void Add(T item)
{
items.Add(item);
}
}
```
And I create an instance of it:
```csharp
var intList = new MyList();
```
Now inside the class I want to know what specific type T is. For example, if T is int, I want to output "int" to the console. I tried using `typeof(T)`, but it doesn't work in static contexts, and I'm not sure how to get the type from an instance. I've also heard that due to type erasure at runtime this can be difficult. In Java I would use Class, but in C# the approach is different. How do I correctly get the type T from an instance of a generic class?