Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Structures Questions
C#.NET structs — 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.
C#.NET — Which statements about classes vs. structs are true? 1) A class is a reference type, whereas a struct is a value type. 2) Objects are created using new, whereas struct variables can be created using new or without new. 3) A struct variable will always be created slower than an object. 4) A struct variable will die when it goes out of scope. 5) An object will die when it goes out of scope.
C#.NET — Is it allowed to declare an empty struct (no fields or members)?
C#.NET — Given the struct below, which is the correct way to assign values to its fields? struct Emp { public string name; public int age; public Single sal; } Emp e = new Emp();
C#.NET — Consider the structure and usage below. Which statements are correct? struct Book { private string name; protected int totalpages; public Single price; public void Showdata() { Console.WriteLine(name + " " + totalpages + " " + price); } Book() { name = ""; totalpages = 0; price = 0.0f; } } Book b = new Book(); Evaluate the following claims: 1) We cannot declare totalpages as protected. 2) We cannot declare name as private. 3) We cannot define a zero-argument constructor inside a struct. 4) We cannot declare price as public. 5) We can define a Showdata() method inside a struct.
C#.NET — How many bytes does the following struct instance occupy? (Assume a 32-bit process / 4-byte object references.) class Trial { int i; Decimal d; } struct Sample { private int x; // 4 bytes private Single y; // 4 bytes private Trial z; // reference (pointer) → 4 bytes on 32-bit } Sample samp = new Sample();
C#.NET — When does a struct variable get destroyed (become eligible for reuse)?
C#.NET — What will be the output of the following program (note value-type copy semantics for struct)? namespace CuriousTabConsoleApplication { 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 + " "); } } }
C#.NET — What will be the output of this program (struct assignment copies the value)? namespace CuriousTabConsoleApplication { struct Sample { public int i; } class MyProgram { static void Main(string[] args) { Sample x = new Sample(); Sample y; x.i = 9; y = x; // copies the struct value y.i = 5; // modifies the copy Console.WriteLine(x.i + " " + y.i); } } }
C#.NET — Identify the correct statement about structs, value types, and the type system.
C#.NET — True or False: structures (struct) are always value types in .NET.
C#.NET — Choose the correct way to declare and initialize a variable of the struct Emp. struct Emp { private string name; private int age; private float sal; } Which one of the following single-line or two-line snippets correctly declares a variable and initializes it?
C#.NET — Trace ref parameter behavior with a struct to determine output. namespace CuriousTabConsoleApplication { struct Sample { public int i; } class MyProgram { static void Main(string[] args) { Sample x = new Sample(); x.i = 10; fun(ref x); Console.Write(x.i + " "); } public static void fun(ref Sample y) { y.i = 20; Console.Write(y.i + " "); } } } What will be printed?
C#.NET — True or False: “The space required for structure variables is allocated on the stack.”
C#.NET — Allocation of struct variables and reference fields. Given: class Trial { int i; decimal d; } struct Sample { private int x; private float y; private Trial z; // reference-type field } Sample ss = new Sample(); Which statement is correct?
C#.NET — Behavior of a struct variable: location, constructors, GC, and inheritance. Given: struct Book { private string name; private int noofpages; private float price; } Book b = new Book(); Which statement is correct?
C#.NET — Select the correct statements about structs (declaration, inheritance, access modifiers, empty structs, field initialization). Which are valid facts?
C#.NET — What happens when assigning one struct to another? Given: struct Address { private int plotno; private string city; } Address a = new Address(); Address b; b = a; Choose the correct effect of “b = a;”.