.net - C# performance question: typeof(MyClass) vs. this.GetType() -
In the first example of the author, using the type of "typeof (MyApp") The square is Typef (Foo) is a fixed type lookup; Essentially this happens at the collection time, so you only get clearly named type. GetType () is a dynamic type lookup; This is a virtual method that calls the runtime and gives you the exact type, even if you are using polymorphism. So this is "slow", theoretically, but it gives you something that you can not get from typef (t). If you need one or the other for your design, then speed is not to be a factor. MyApp . Is there any reason for this? GetType () , display-wise? Because I think that
this.GetType () is more secure than possible copy-paste errors when copying to another category.
Comments
Post a Comment