C# Programming - Structures - Discussion

Discussion Forum : Structures - General Questions (Q.No. 8)
8.
Which of the following will be the correct result of the statement b = a in the C#.NET code snippet given below?
struct Address
{
    private int plotno;
    private String city; 
}
Address a = new Address(); 
Address b; 
b = a;
All elements of a will get copied into corresponding elements of b.
Address stored in a will get copied into b.
Once assignment is over a will get garbage collected.
Once assignment is over a will go out of scope, hence will die.
Address of the first element of a will get copied into b.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
2 comments Page 1 of 1.

Mohammad Adil said:   9 years ago
To copy any struct variable the right side variable must be initialized or populated.

But here the fields of struct have no any initialized value so, all the element of a copied to b but if there is the value of fields then the value are not initialized.

Kazeem said:   1 decade ago
Since Structure is a value type, All the elements of 'a' will be copied to 'b'.

Consider Below Example,

int i=10; //value type variable.
int j; // value type variable.

Now, j=i; //j contains the value 10,as the value of i is copied to j.

Post your comments here:

Your comments will be displayed after verification.