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# interview questions and answers

1
What is a constant in C# ?
  1. Constants in C# are immutable values whose value must be know to compiler during compilation time and must not be changed through out the program life time.
  2. Constants in C# are mutable values whose value can be changed in constructors.
  3. Constants in C# are immutable values whose values are assigned in constructors.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
2
Which of the following statements is true about Constants ?
  1. You can assign a value to a constant after it is declared.
  2. Constant must be initialized when it is declared.
  3. Constant can be initialized in a constructor.
  4. Constants are object specific.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
4
Which of the following statements are true about below given code?
public class A
{
    public const float PI = 0.141f;
    public void M(float f) {PI =f;}
}
public class B
{
     public static void Main()
     {
         A a=new A();
         a.M(9.101f);
        Console.write(A.PI);
     }
}
  1. Output becomes 9.101
  2. Within the Method we should access 'PI' by using object of class A.
  3. We are not allowed to change value of constants once they are initialized during declaration time.
  4. 2,3 are correct.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
8
How to access a constant field declared in a class from another class?
  1. By using object of a class.
  2. By using name of the class.
  3. Can not access outside of the class.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
9
How do you access a readonly field declared in a class from another class?
  1. By using object of the class.
  2. By using name of the class.
  3. Readonly variable can not be accessed outside of the class.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
12
Which of the following statements is true about given code?
public class Test
{ 
   public static readonly int x = 90;
   public readonly int z;
   public static readonly int y = 10;
   public readonly int p = x + 20;  
}
  1. Without initialization, declaration of read-only variables not allowed.
  2. We can not make read-only variables as static.
  3. We can not give reference of one read-only variable to other read-only expression.
  4. Code will be compiled successfully.
Show Answer
Share Facebook gmail Twitter
13
Which of the following statements is true about readonly variables?
  1. We can assign the data to the readonly variable directly during declaration time.
  2. We can not change data present in read-only variable once they have declared.
  3. Readonly variables are class specific.
  4. All the above.
Show Answer
Share Facebook gmail Twitter
14
Which of the following statements is true about readonly variables?
  1. Read-only variables are class specific.
  2. We can assign the data to the read-only variable in the constructor.
  3. Readonly and constants both are same.
  4. All the above.
Show Answer
Share Facebook gmail Twitter
15
Which of the following statement is true about given Code?
public class Test
{   
    public  readonly int x = 90;   
    public readonly int z;
    public Test(int r)
    {
        z = r;
        x = z + 1;
    }
}
  1. Code will be compiled successfully.
  2. Error, read-only variable should be initialized either during declaration or in constructor .
  3. Error, we can not assign the data to the read-only variables while declaring the variable .
  4. Error, we can not assign the data to the read-only variables in constructor.
Show Answer
Share Facebook gmail Twitter
16
What is the output of the below given code ?
public class Test
{
     public const string d = "skillgun";
}
  1. Code will be compiled successfully.
  2. Compilation error throwing the reason as " only value types can be declared as constants ".
  3. Compilation error stating the reason as " A const field of a reference type must assigned  with null".
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
17
What is the output of the below given code ?
public class D {   }
public class Test
{
          public const D d = new D();
}
  1. Code will be compiled successfully.
  2. Compilation error throwing the reason as " only value types can be declared as constants ".
  3. Compilation error stating the reason as " A const field of a reference type other than string can only be initialized with null".
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :