Does t.GetType() return the same Type instance?
c#, types
Solution
MSDN: Object.GetType Method:
For two objects x and y that have identical runtime types, `Object.ReferenceEquals(x.GetType(),y.GetType())` returns true.
So, yes.
Problem
I'm thinking about storing a `Type` variable in my objects. However, there can be quite a lot of them, but the amount of different types is not so large. I'm worried about using a lot of memory to store the `Type` in all those objects, when the type could be the same for many of them. Is a new instance of `Type` created every time I look up the type of something, with either `t.GetType()` or `typeof(T)`? Or is it actually the same? If it was the same I wouldn't have to worry about the memory. Note that I have considered generics, which is not an alternative in this case.