.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 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.

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.

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -