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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:38:20+00:00 2026-05-15T22:38:20+00:00

struct is a value type in C#. when we assign a struct to another

  • 0

struct is a value type in C#. when we assign a struct to another struct variable, it will copy the values. how about if that struct contains another struct? It will automatically copy the values of the inner struct?

  • 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-15T22:38:21+00:00Added an answer on May 15, 2026 at 10:38 pm

    Yes it will. Here’s an example showing it in action:

    struct Foo
    {
        public int X;
        public Bar B;
    }
    
    struct Bar
    {
        public int Y;
    }
    
    public class Program
    {
        static void Main(string[] args)
        {
            Foo foo;
            foo.X = 1;
            foo.B.Y = 2;
    
            // Show that both values are copied.
            Foo foo2 = foo;
            Console.WriteLine(foo2.X);     // Prints 1
            Console.WriteLine(foo2.B.Y);   // Prints 2
    
            // Show that modifying the copy doesn't change the original.
            foo2.B.Y = 3;
            Console.WriteLine(foo.B.Y);    // Prints 2
            Console.WriteLine(foo2.B.Y);   // Prints 3
        }
    }
    

    How about if that struct contains another struct?

    Yes. In general though it can be a bad idea to make such complex structs – they should typically hold just a few simple values. If you have structs inside structs inside structs you might want to consider if a reference type would be more suitable.

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

Sidebar

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer LogCollector's source code is freely available and does just that.… May 16, 2026 at 3:36 pm
  • Editorial Team
    Editorial Team added an answer In UTF-8, a non-leading byte always has the top two… May 16, 2026 at 3:36 pm
  • Editorial Team
    Editorial Team added an answer You just use the custom membership providers. Here is a… May 16, 2026 at 3:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

can we assign null value to struct type of variable? struct MyStruct { }
I understand the theoretical concept that assigning one reference type variable to another, only
I frequently read that struct s should be immutable - aren't they by definition?
How do I default-initialize a local variable of primitive type in C++? For example
A set of APIs that I commonly use follow a linked-list pattern: struct SomeObject
I am using a struct and I want to initialize a maximum of 10
I'm having some headaches using Structures and functions that return Nothing in VB.NET. Let
I'm trying to traverse a binary tree in C. My tree contains an AST
I was told that these types, that are visible in there own unique translation
C++ typedef struct someStruct { int val1, val2; double val3; } someStruct; someStruct a

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.