I know that struct is a value type , that means it defined on stack .
But I can do A a = new A(); (A my struct of course). and it defined on heap , and only the reference variable is on stack.
Can you explain me this one please .
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Value types are stored on the stack sometimes. It’s a complex topic and usually the exact storage of a variable (stack or heap) is irrelevant for programming issues. The real difference between value and reference types lies in their behaviour (for example, value types are always copied by value).
Eric Lippert covers this issue in detail: