Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6547001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:46:37+00:00 2026-05-25T11:46:37+00:00

I am making a XNA game and I am calling following code 2 to

  • 0

I am making a XNA game and I am calling following code 2 to 20 times per update. I tried googling and it seems like this is semi-slow, so I just thought I’d ask if there is any faster way to compare types?

Code:

    public Modifier this[Type type]
    {
        get
        {
            for (int i = 0; i < this.Count; i++)
            {
                if (this[i].GetType() == type)
                {
                    return this[i];
                }
            }

            throw new NotImplementedException("Fix this");
        }

        set
        {
            for (int i = 0; i < this.Count; i++)
            {
                if (this[i].GetType() == type)
                {
                    this[i] = value;
                }
            }

            if(System.Diagnostics.Debugger.IsAttached)
                System.Diagnostics.Debugger.Break();
        }
    }

This code is in ModifierCollection class which inherits from a List. Modifier is a part of particle engine. Also, my game isnt in condition where I can actually test this yet so I cant test this, but this should work right?

I read something about RunTimeTypeHandles which should be faster, should I use it?

EDIT: What I am aiming to do with this is that I can do the following:

    (particleEffect["NameOfEmitter"].Modifiers[typeof(SomeCoolModifier)] as SomeCoolModifier).Variable = Value;

Basically I just want to change the value of some Modifiers in runtime.

EDIT 2: I just realized that I can just save the reference of Modifier to the class where I am at the moment calling this 😛 Maybe not as clean code if I have 5-10 modifiers but should remove this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:46:38+00:00Added an answer on May 25, 2026 at 11:46 am

    If you don’t need any of the extra functionality exposed by Type, and you’re only concerned with absolute equality between types–i.e., you don’t need to support inheritance–RuntimeTypeHandle is the fastest way to do this comparison.

    Really, though, I would question whether this isn’t a weakness of your class design. Unless you have a compelling reason to check the type directly, it’s probably better to expose some sort of value (probably an enum) on your objects that represents what they are, and do your comparisons against that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following this tutorial attempting to learn XNA, but I'm having issues making my
I'm making a highscorelist for my XNA game. I would like to make it
I'm making a simple 2 player game in XNA and started looking into saving
I am making a game using C# with the XNA framework. The player is
I'm making a simple game in XNA (for Windows, if that makes a difference),
I'm making a game in XNA, and I noticed that when I publish the
I'm making a game in XNA and currently I'm checking the coordinates of the
I'm making a drum machine. From what I've read, it looks like the XNA
I have a question about a XNA game I'm making, but it is also
I'm making a 3D game in XNA using Ox Engine. There is very little

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.