C# Programming - Structures

Exercise : Structures - General Questions
  • Structures - General Questions
6.
Which of the following statements is correct about the C#.NET code snippet given below?
class Trial
{ 
    int i;
    Decimal d;
}
struct Sample
{
    private int x;
    private Single y;
    private Trial z;
}
Sample ss = new Sample();
ss will be created on the heap.
Trial object referred by z will be created on the stack.
z will be created on the heap.
Both ss and z will be created on the heap.
ss will be created on the stack.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

7.
How many bytes will the structure variable samp occupy in memory if it is defined as shown below?
class Trial
{ 
    int i; 
    Decimal d;
}
struct Sample
{
    private int x; 
    private Single y; 
    private Trial z;
}
Sample samp = new Sample();
20 bytes
12 bytes
8 bytes
16 bytes
24 bytes
Answer: Option
Explanation:
No answer description is available. Let's discuss.

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.

9.
Which of the following statements are correct?
  1. A struct can contain properties.
  2. A struct can contain constructors.
  3. A struct can contain protected data members.
  4. A struct cannot contain methods.
  5. A struct cannot contain constants.
1, 2
3, 4
1, 2, 4
3, 5
Answer: Option
Explanation:
No answer description is available. Let's discuss.

10.
C#.NET structures are always value types.
True
False
Answer: Option
Explanation:
No answer description is available. Let's discuss.