Select chapter



Basics (2.papers)
Data Types (2.papers)
enums (2.papers)
OOPS (4.papers)
Arrays (1.papers)
Structs (2.papers)
Properties (2.papers)
Strings (2.papers)
Interfaces (1.papers)
Constructors (2.papers)
Ref-Out-Keywords (1.papers)
Collections (2.papers)
Generics (1.papers)
Hide

Sponsored Links


  

c# structs interview questions and answers

1
What is a structure or struct in c# ?
  1. Built in value types
  2. Reference types
  3. User defined value types
  4. User defined reference types
Show Answer
Share Facebook gmail Twitter
2
How to declare a struct in C# language ?
  1. public struct StructName { .... some code goes here ... }
  2. public structure  StructName { .... some code goes here ... }
  3. public class struct StructName { .... some code goes here ... }
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
3
Which of the following statement is not true about Structs in C#.NET?
  1. Structs can implement an interface, but a struct cannot inherit from another struct or from another class.
  2. Struct members cannot be declared as protected.
  3. It is an error to initialize an instance field in a struct.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
5
What is the difference between a class and a struct in c# ?
  1.  1. struct is a value type and class is a reference type.
     2. struct cannot contain parameter less constructors where as class can.
     3. struct fields cannot be initialized directly where as class fields can be.
     4. structs cannot contain destructors but a class can.
     5. inheritance is not possible on structs but a class can inherit from another class.
  2.  1. struct is a reference type and class is a value type.
     2. struct can contain parameter less constructors where as a class can not.
     3. struct fields cannot be initialized directly where as class fields can be.
     4. structs cannot contain destructors but a class can.
     5. inheritance is not possible on structs but a class can inherit from another class.
  3. There is no difference between a struct and a class.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
13
How to initialize the c# struct ( Identify the correct syntax )?
public struct Student
{
    public String name; 
    public int age; 
    public int sid;
}
  1. Create a parameterized constructor in Struct and assign data to struct variables .
  2. Student oStudent=new Student();
    oStudent.name="ashok";
    oStudent.age=23;
    oStudent.sid=19;
  3. Student s;
    s.name="harish";
    s.age=27;
    s.sid=21;
  4. All of the above.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
15
Which of the following statement is true about the following code ?
 public struct RetailShop
    {        
       public static string  item;
       public static double itemprice;
   }
public struct Shop : RetailShop
    {
            public static string item;
            public static double itemprice;
      }
  1. Code will generate a compilation warning.
  2. Code will compile successfully but will give run-time exception.
  3. Compiled successfully but we cant access.
  4. Compilation error because inheritance is not possible on structs.
Show Answer
Share Facebook gmail Twitter
16
Which of the Following Statement is true in the below given code?
   public interface ISkillGunCalc
    {
        void Add(int x, int y);
        void Sub(int x, int y);
    }
    public struct SkillGunCalc :  ISkillGunCalc
    {
        public void Add(int x, int y)
        {
            int z = x + y;
        }
    }
  1. Need to declare struct as abstract.
  2. Can not implement interfaces in structs.
  3. Declare void Sub(int,int) as abstract in struct S.
  4. We should give implementation to all the methods which are present in ISkillGunCalc otherwise
    we will get compilation error.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
18
Is it possible to create an object of primitive types using new keyword ?
  1. Yes. Use the syntax as shown below.
    int i=new int ();
  2. No.
  3. Yes . For creating primitive type object we must create a new derived type and then we have to create object.
    Ex: public class A:Int {}   
    A a=new A();
Show Answer
Share Facebook gmail Twitter
19
Which is the base type for all Structs in C# ?
  1. Sytem.Struct
  2. System.object
  3. System.ValueType
  4. System.Type
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :