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

  • Home
  • SEARCH
  • 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 6898727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:19:58+00:00 2026-05-27T07:19:58+00:00

Trying to keep my C# code optimized, I found that if I have a

  • 0

Trying to keep my C# code optimized, I found that if I have a list of structure elements, each insertion would be a full copy – something that I would like to avoid.

In C++ I would simply keep a list of pointers and so I was wondering if I can do the same using C#, maybe by having the list as a list of references to the structure.
Unfortunately the structure cannot be turned into a class as it is part of the XNA library (Vector3, Matrix, etc…)
In any case – how would the format and usage look like if it’s possible?

Thanks.

  • 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-27T07:19:59+00:00Added an answer on May 27, 2026 at 7:19 am

    No, basically. Options:

    • use a class (you’ve already said you can’t)
    • box it
    • write a class that wraps it (essentially, manual boxing)
    • use an array, and access it only directly in the array by index (without copying into a variable); this is then talking directly to the item in the array (no copy)

    As an example of the last;

    if(arr[idx].X == 20) SomeMethod(ref arr[idx]);
    

    Both the .X, and any usage within SomeMethod, are accessing the value directly in the array, not a copy. This is only possible with vectors (arrays), not lists.

    One reason a list of refs to structs isn’t possible: it would allow you I store, in the list, the address of a variable on the stack; the array usually outlives the variable on the stack, so that would be ludicrously unsafe

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

Sidebar

Related Questions

I have an alert script that I am trying to keep from spamming me
Ever since reading Clean Code I have been trying to keep my code descriptive
I am trying to keep my code as secure/clean as possible. If I have
I am trying to keep functions related to each other close together. What would
I'm trying to keep my code clean and keep the number of files down.
I'm trying to adopt some best practices to keep my python code efficient. I've
I'm trying to learn about this feature of javascript I keep seeing in code,
I keep getting this error while trying to modify some tables. Here's my code:
I'm trying to take an existing bunch of code that was previously on a
I have been having a small problem that I can't by-pass it, I keep

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.