c# - GetType() == type perfomance question -


I am making an XNA game and I am calling the following updates 2 to 20 times the code. I tried googling and it seems that it is half slow, so I thought I was asking what kind of fast way to compare the type?

code:

  Public modifier for this [type type] {for (int i = 0; i & lt; this.Qount; i ++) {if ( It [I.] Type GETType () ==) {Please return this [ii]; }} New NotImplementedException Throw ("Fix It"); } Set {for (int i = 0; i & lt; this.Qount; i ++) {if (this [i]. Type GetType () ==) {this [i] = value; }} If (System. Diagnostics.Debugor.ISAcredited) system. Diagnostics. Debugger. Break (); }}   

This code is in the modifier collection section which comes from a list. The modifier is a part of the particle engine. In addition, my game is not in a situation where I can actually do this test, so I can not test it, but should it work right?

I read something about runtime typhanies, which is fast, should I use it?

Thanks a lot!

Edit: What I'm aiming to do with it is that I can do the following:

  (particleEffect ["nameOfEmitter"]. Audifier [typef (Some basic modifier)] as some basic modifier. Variable = value;   

Actually I just want to change the value of some modifiers in the runtime.

2 Edit: I Realized that I can only save the modifier's reference in the classroom where I am currently calling it P: Maybe I do not have a clean code when I have 5-10 modifiers, but this problem should be removed.

if You do not need any additional functionality that is made known to you by type , and you only relate to full equality between types - that is, you do not need it - Support legacy - runtime typing handles < / Code> This is the fastest way to compare.

In fact, But, I question that this is not the weakness of your classroom design. Unless you have a compelling reason to examine the type directly, then it may be better to expose some types of value (possibly an enum) on your objects , Which they are, and compare it against you.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

memcached - Django cache performance -

java : convert string value to int -