C# Programming :: Structures
-
Which of the following will be the correct output for the C#.NET program given below?
namespace FreshergateConsoleApplication { struct Sample { public int i; } class MyProgram { static void Main() { Sample x = new Sample(); x.i = 10; fun(x); Console.Write(x.i + " "); } static void fun(Sample y) { y.i = 20; Console.Write(y.i + " "); } } }
-
Which of the following is the correct way of setting values into the structure variable e defined below?
struct Emp { public String name; public int age; public Single sal; } Emp e = new Emp();
-
Which of the following is the correct way to define a variable of the type struct Emp declared below?
struct Emp { private String name; private int age; private Single sal; }
- Emp e(); e = new Emp();
- Emp e = new Emp;
- Emp e; e = new Emp;
- Emp e = new Emp();
- Emp e;
-
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();
-
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();
-
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;
-
Which of the following statements are correct?
- A struct can contain properties.
- A struct can contain constructors.
- A struct can contain protected data members.
- A struct cannot contain methods.
- A struct cannot contain constants.
A.
All elements of a will get copied into corresponding elements of b. |
B.
Address stored in a will get copied into b. |
C.
Once assignment is over a will get garbage collected. |
D.
Once assignment is over a will go out of scope, hence will die. |
E.
Address of the first element of a will get copied into b. |