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;
Discussion:
2 comments Page 1 of 1.
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.
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.
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers