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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:35:01+00:00 2026-06-17T09:35:01+00:00

Lets say that i have a struct like that: public struct MyCustomDataset : IEnumerable<float>

  • 0

Lets say that i have a struct like that:

public struct MyCustomDataset : IEnumerable<float> {
    public float v1;
    public float v2;
    public float v3;

    public MyCustomDataset(float v1, float v2, float v3) {
        this.v1 = v1;
        this.v2 = v2;
        this.v3 = v3;
    }

    // Enumerable impl
    public IEnumerator<float> GetEnumerator() {
        yield return v1;
        yield return v2;
        yield return v3;
    }
    IEnumerator IEnumerable.GetEnumerator() {
        return GetEnumerator();
    }
}

And methods like this:

public static MyCustomDataset test() {
    return new MyCustomDataset(1,2,3);
}

public static void test2() {
    MyCustomDataset ds = test();
    /* doing stuff with ds */
}

I want to know if its more optimal then if MyCustomDataset was class instead of struct. I need to know that, because im calling test() in apps main loop, so MyCustomDataset is going to be allocated in every apps iteration. Because of that, i wont make MyCustomDataset an class, because it would be like performance suicide. Im cosidering using struct, because im suspecting that it can behave more or less like primitive type in that case.

Would it be ok with performance ?

Im not going to assign MyCustomDataset to any class field, I will only read it in methods body, and maybe will pass it into a few method calls, so it will be present in few local scopes.

  • 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-06-17T09:35:02+00:00Added an answer on June 17, 2026 at 9:35 am

    You:

    because it would be like performance suicide

    Why do you think so? What difference between structs and classes are you refering to?

    I think you should go with a struct if you feel it’s more or less like “a primitive type” (your words). This is just three float values (possibly a total of 96 bits), so it’s small enough for a value type. But if you stick to a struct, make the fields readonly.

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

Sidebar

Related Questions

Lets say I have an interface like this: public interface MyInterface { int Property1
Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
Let's say I have a struct that contains local environments: public struct Environments {
Lets say that I have the following code: public class Shelter<A extends Animal, B
Lets say that i have the following array : float QuadVertices[4 * 2]; float
Lets say you have various objects of arbitrary type that you would like to
Let’s say that we have a very simple QML file, like this one: import
Suppose I have some simple struct like this: public struct WeightedInt { public int
Let's say I have this struct in ANSI C: typedef struct _point { float
Lets say that i have 2 pages: index.php and service.php index.php sends an http-post

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.