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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:20:29+00:00 2026-05-25T15:20:29+00:00

When I first saw the value types in C#, the first thing I thought

  • 0

When I first saw the value types in C#, the first thing I thought was “wow, what a great optimization”, the second thing is, “do we really need a new language construct? can’t we do that with annotations instead?”.

The idea is, given a class, we’ll use it as we always did

class A {int i;}
class B {
    A m_a;
    int F(A a) {m_a = a;}
}

On a whim we’ll change A to be

[ValueType]
class A {int i;int j;}

And the compiler will automatically convert class B to be

class B {
#region A
    int A_i;
    int A_j;
#endregion
int F(/*A param*/int i,int j) {
#region A_assign
    A_i = i;
    A_j = j;
#endregion
}

Bear in mind, that if the compiler doesn’t wish to optimize some instance – it doesn’t have to. It would work either way.

It might arise problems with templates,

int f<T>() {
    T t; // how much stack should I allocate
}

but I’m not sure it’s much worse than the current situation. I’m actually not sure what happens now (is f<struct_of_100_bytes> a different function than f<int>?).

  • 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-25T15:20:30+00:00Added an answer on May 25, 2026 at 3:20 pm

    Now imagine inheritance. Or arrays. Or arguments. Or generics. Or implementing an interface. Or assigning to object/dynamic.

    And keep in mind that the runtime supports multiple compilers.

    Having a specific keyword (struct) rather than an attribute is not really a big change (indeed, in terms of the CLI everything is called a class), but the overall situation is much more complex than your example.

    Basically, struct does pretty-much everything you mention, and works in all the scenarios listed. Since it generally (for locals) uses the stack, it already behaves much like you describe.

    Re the “separate function” question; firstly, generics are not “templates” (it is runtime vs compile-time). But generics get a JIT per value-type, and a single JIT per reference-type (because indeed: the stack layout changes.

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

Sidebar

Related Questions

I very rarely meet any other programmers! My thought when I first saw the
I saw this keyword for the first time and I was wondering if someone
Saw this piece of code in a Ruby on Rails book. This first one
I'm giving my first steps on Python. I saw that we don't have switch
Ok, First off, I am not a mysql guru. Second, I did search, but
I was looking through new stuff added to jQuery 1.7 and I saw they
I'm asking this question because it isn't the first time I saw this coding
I want to read two input values. First value should be an integer and
First I want to say I saw a site: https://cwiki.apache.org/WICKET/autocomplete-using-a-wicket-model.html Still I have some
I thought I had it figured out but now I'm missing something. First I

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.