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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:01:40+00:00 2026-05-23T13:01:40+00:00

I have an hierarchical structure of classes like this public class Class1 { internal

  • 0

I have an hierarchical structure of classes like this

public class Class1
{
    internal DateTime time = DateTime.Now;
}

public class Class2
{
    internal Class1 C1;

    public Class2(Class1 c1) { C1 = c1; }

    public DateTime Time { get { return C1.time; } }
}

public class Class3
{
    internal Class2 C2;

    public Class3(Class2 c2) { C2 = c2; }

    public DateTime Time { get { return C2.Time; } }
}

public class Class4
{
    internal Class3 C3;

    public Class4(Class3 c3) { C3 = c3; }

    public DateTime Time { get { return C3.Time; } }
}

I wondered when I call

Class4 C4 = new Class4(.....);  
Console.WriteLine(C4.Time);

will the ValueType data (it is DateTime in this scenario) be copied 4 times or will JIT compiler optimize the code and regenerate it as an inlined version like C4.C3.C2.C1.time;

C# compiler does not do any optimization. ILDASM generated code is here:

// get { return C3.Time; }
.method public hidebysig specialname instance valuetype [mscorlib]System.DateTime 
        get_Time() cil managed
{
  // Code size       12 (0xc)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldfld      class CSTester.Class3 CSTester.Class4::C3
  IL_0006:  callvirt   instance valuetype [mscorlib]System.DateTime CSTester.Class3::get_Time()
  IL_000b:  ret
} // end of method Class4::get_Time

// get { return C2.Time; }
.method public hidebysig specialname instance valuetype [mscorlib]System.DateTime 
        get_Time() cil managed
{
  // Code size       12 (0xc)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldfld      class CSTester.Class2 CSTester.Class3::C2
  IL_0006:  callvirt   instance valuetype [mscorlib]System.DateTime CSTester.Class2::get_Time()
  IL_000b:  ret
} // end of method Class3::get_Time

EDIT: Code is compiled in release mode with optimizations enabled.

  • 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-23T13:01:41+00:00Added an answer on May 23, 2026 at 1:01 pm

    Eric Lippert says I don’t know much more eloquently than me.

    On a side note,

    int sizeInBytes;
    unsafe
    {
        sizeInBytes = sizeof(DateTime);
    }
    

    results in a value of 8 for me but it would be unsafe to rely on it. The copying of 24 bytes is not worth worrying about. If it is, perhaps a lower generation of language should be used for this part of the code.

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

Sidebar

Related Questions

I have a hierarchical structure like this: class Node { Node Parent; string Name;
I have a hierarchical class structure like this: Category -> Template -> Instance A
I have a data structure that looks like this: public class Node { public
i have a table with hierarchical structure. like this: (source: aspalliance.com ) and table
In flex 3 I have a hierarchical data structure. I would like to display
I have a hierarchical query to track a reporting structure. This almost works, except
I have a requirement to represent a hierarchical structure in a class within c#.
I have a hierarchical table on Oracle pl/sql. something like: create table hierarchical (
I have a hierarchically nested associative array. It looks like this: A = {
I have a hierarchical structure stored in a table. Each element has a pointer

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.