C# Interview Questions and Answers

Q-1. What is the default access modifier of the method?
Answer: Private

Q-2. What Will Be The Output Of The Following Code Snippet:

  public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(Math.Round(0.5));
            Console.WriteLine(Math.Round(1.5));
            Console.WriteLine(Math.Round(2.5));
            Console.WriteLine(Math.Round(3.5));
            Console.WriteLine(Math.Round(4.5));
            Console.WriteLine(Math.Round(5.5));
            Console.WriteLine(Math.Round(6.5));
            Console.WriteLine(Math.Round(7.5));
            Console.WriteLine(Math.Round(8.5));
            Console.WriteLine(Math.Round(9.5));
            Console.WriteLine(Math.Round(10.5));
            Console.WriteLine(Math.Round(11.5));
        }              
    }

Output:

Math.Round() Method

Math.Round() Method

 

Explanation: 

You will be surprised to see the strange out. This is because of the following definition of Math.Round() method on MSDN blog.

Decimal Math.Round(Decimal d) :  Rounds a decimal value to the nearest integer, and rounds midpoint values to the nearest even number.

(A) public class ShopList : IEnumerator, IEnumerable { // Class implementation }
(B) public class ShopList : IBindingList { // Class implementation }
(C) public class ShopList : ICollection { // Class implementation }
(D) public class ShopList : IDictionary { // Class implementation }
Answer: public class ShopList : IEnumerator, IEnumerable { // Class implementation }
(A) int[][] myArray;
(B) int[,] myArray;
(C) System.Array[2] myArray;
(D) int[2] myArray;
Answer : int[,] myArray;

Q-5 : How many web.config files that can be there an ASP.NET application?

(A) only one

(B) more than one

(C) only two

(D) up to 10

Answer : more than one

Q- 6 : Code that targets the Common Language Runtime is known as

(A) Legacy
(B) Managed Code
(C) Unmanaged
(D) Native Code
Answer: Managed Code

Q- 7 : In the NUnit test framework, which attribute must adorn a test class in order for it to be picked up by the NUnit GUI?

(A) TestFixtureAttribute
(B) TestClassAttribute
(C) TestAttribute
(D) NUnitTestClassAttribute
Answer : TestFixtureAttribute
Answer : No

Q- 9 : What compiler switch creates an XML file from the XML comments in the files in an assembly?

(A) /text
(B) /xml
(C) /doc
(D) /help
Answer : /doc
(A) 1, 2
(B) 1, 5
(C) 3, 4
(D) 4, 5
Answer :3, 4
(A) datareader
(B) dataset
(C) datatabel
(D) all
(A) Yes, and we can access them
(B) No, and we can not access them
(C) Yes, but we can not access them
(D) All of the above are wrong
Answer: Yes, and we can access them. 

They are inherited in the sense that memory space is allocated for them and they “exist” within the subclass instance. But they are not accessible, not visible in the driven class, so it looks like that they are not inherited. To access variable’s of the base class into the subclass, use protected instead of private.

Written by 

One thought on “C# Interview Questions and Answers

  1. Pingback: Maria Smith

Leave a Reply

Your email address will not be published. Required fields are marked *