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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:49:06+00:00 2026-05-17T21:49:06+00:00

Possible Duplicate: How does .net managed memory handle value types inside objects? I have

  • 0

Possible Duplicate:
How does .net managed memory handle value types inside objects?

I have a class as below

public class MyClass
{

  public List<RequestRow> RequestRow { get; set; } 
  public List<int> intList { get; set; } 
  public string ErrorMessage { get; set; }
  public string SuccessMessage { get; set; }

  int i;
  DateTime dt = DataTime.Now;

  public void SomeMethod()
  {
         //some operation
  }
}

The question is Which will go to heap and which to stack? And why?

Means MyClass , the properties, fields, and the method will go where..heap or stack?

Recently I found this question in an interview and is curious to know about this

Edited

I liked Mr.John’s answer and my doubts have been cleared..

I have 2 more questions to ask…

a) When will int i and DateTime dt be treated as Value type and will be put into stack

b) If I have an Interface say

namespace namespace1
{
    public interface IXLView
    {
        ExcelXP.Application ExcelApp { get; }
        ExcelXP.Workbook CurrentWorkBook { get; }
        ExcelVersion ExcelVersion { get; }       
    }

    public enum ExcelVersion
    {
        Excel2003, Excel2007
    }
}

then where will be the objects be placed in this case..Stack or Heap?
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-17T21:49:07+00:00Added an answer on May 17, 2026 at 9:49 pm

    Which will go to heap and which to stack? And why?

    Everything there goes onto the heap. Why? Because the heap is for storage of data where the lifetime of the storage cannot be determined ahead of time. In your example the lifetime of everything – the numbers, the strings, the lists – cannot be known ahead of time, so they all have to go onto the heap so that the garbage collector can determine when that storage is dead.

    When will int i and DateTime dt be treated as Value type and will be put into stack?

    They will always be treated as value types because they are value types. That is, they will be copied by value and contain their own values.

    They will never be put onto the stack because the lifetimes of their storages cannot be known ahead of time.

    If I have an interface then where will be the objects be placed in this case … stack or heap?

    The question doesn’t make any sense. You’ve only got types, no objects. What objects are you talking about?

    But the answer is the same: the objects will be put on the stack if the lifetimes of their storages are known ahead of time; otherwise, they’ll be put on the heap to be garbage collected.

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

Sidebar

Related Questions

Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: What does map(&:name) mean in Ruby? I was watching a railscast and
Possible Duplicate: Why does C# not provide the C++ style ‘friend’ keyword? I'd like
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: What Ruby IDE do you prefer? I've generally been doing stuff on
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the

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.