Something I’ve been thinking about from time to time: Why is the typeof operator needed in C#? Doesn’t the compiler know that public class Animal is a type just by the very definition? Why do I need to specify SomeMethod(typeof(Animal)) when I need to reference a type?
Something I’ve been thinking about from time to time: Why is the typeof operator
Share
typeof(Class)is the only way to express Type as a literal. When you writeClass.SomeFieldyou mean static field. When you writetypeof(Class).SomeFieldyou reference field of object of classTypethat represents your class.