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 6005881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:27:37+00:00 2026-05-23T01:27:37+00:00

I have a struct with some fields. One of the fields is of a

  • 0

I have a struct with some fields. One of the fields is of a generic type. The generic type could be either a reference type or a value type.

I want to force that it is stored as a reference internally, to avoid that the struct gets too large.

struct Foo<T>
{
  T field; // should be a reference
}

I know I could use object or T[], but both is awkward. Isn’t there something like a generic Reference type?

struct Foo<T>
{
  Reference<T> field;
}

Yes, sure, I could write my own. But I’m trying to avoid that

  • 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-23T01:27:38+00:00Added an answer on May 23, 2026 at 1:27 am

    If you’re trying to be absolutely sure any Value Type is boxed, store it in an object field and use a property to enforce the generic constraint; ie:

    struct Example<T>
    {
        private object obj;
        public T Obj
        {
            get
            {
                return (T)obj;
            }
            set
            {
                this.obj = value;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to let MongoDB dynamically assign a value to one of the fields
I have two structs containing some fields: struct MyNodeData, and struct MyEdgeData. When I
I want to have named fields rather than indexed fields, but for some usage
I have a utility struct defined in a library API, that has four fields,
I have some struct: struct A { const char* name_; A* left_; A* right_;
I have some null struct, for example: struct null_type { null_type& someNonVirtualMethod() { return
I have a struct that looks like this: typedef struct _my_struct { float first_vector[SOME_NUM][OTHER_NUM];
I have the following code in specman: var x := some.very.long.path.to.a.variable.in.another.struct; while (x ==
I have C dll with some complicated struct and I ma really a newbie
I have a BST library in wich I store some structs : struct bst_node

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.