C# Interview Question and Answers

Hello programming guys, today I am here to show you few C# Interview questions on different topics. I am giving detailed answers to each question, for quick learning and easy updating. I have designed 10 C# Interview questions for freshers to crack their first job with ease. Check out below to find both C# interview questions and answers, without digging much for each topic and refer too many sites. I gave examples to the required  c# interview questions to provide you with a clear idea.

Cracking your interview is much comfortable with our C# Interview questions and answers. All the best guys.

C# interview questions for freshers


1.Explain Sealed Class in C#?

Ans: A sealed class in c# is used to restrict the class from being inherited from other classes in a program. “Sealed” modifier is used along with methods to avoid being overridden in the child classes. Sealed class restricts the inheritance features of object-oriented programming.

2. Explain sealed class in c# with an example?

Ans:

Class one {}

 

Sealed class two: one {}

 

Sealed methods –

 

Class ABC

{

Protected virtual void primary () {}

Protected virtual void secondary () {}

}

 

Class PQR : ABC

{

Sealed protected override void primary () {}

Protected override void secondary () {}

}

If any class inherits from class “PQR” then method – “primary” cannot be overridable as that method has sealed in class PQR.

3. Which menthod do you use to convert a string to date time in C#?

Ans: we can use Convert.ToDateTime(string) or DateTime.Parse(string) methods to convert a string to date time depending upon the type of date format stored in a string.Example 1: String strDate = “03/06/2018”;DateTime Date = Convert.ToDateTime(strDate); Example 2:String strDate = “2018 – 06 – 03 ”;DateTime Date = DateTime.Parse(strDate);

4. What is an enum in c# and how do you declare a variable in the enum?

Ans: Enum is a set of named integer constants, declared with “enum” keyword. C enumerations can have its own values and cannot inherit or pass inheritance. In enum variable are declared under string braces and separated by a comma.Example:enum letters {abc, def, ghi, jkl};

5. Explain the difference between string and string builder in C#?

Ans: String is an object type in c# whose value is a text and a collection of characters without any null terminating character at the end. String data type is used to store a word in c# within double quotes.Whereas a string builder is used to store a modified string in C# programming language. String builder allows you to expand the number of characters in the string while modifications, without any new object memory creation but only expands the memory dynamically to accommodate the modified string.

6. What is a jagged array in C#?

Ans: jagged array is a special concept in C# to store arrays as elements in an array. A jagged array is an array whose elements are also arrays of different sizes and dimensions. Length of all the stored arrays differ.

7.      Convert the following c# code to vb.net code       

String strDate = “03/06/2018”;

DateTime Date = Convert.ToDateTime(strDate);

MessageBox.Show ( Date.Day + “ “ + Date.Month + “ “ + Date.Year );

Ans:

Dim strDate As String = “03/06/2018”

Dim Date as DateTime  = Convert.ToDateTime(strDate);

MsgBox(Date.Day & “ “ & Date.Month & “ “ & Date.Year)

8. What is an Extension method in C# and can extension methods access private members?

Ans: Extension methods in C# is new feature that enables to add methods to existing types without creating new derived types and also does not modify the original types.An extension method cannot access private members, as these are special type of static methods to existing static class.

9. What is early binding and late binding in C#?

Ans: With early bunding, as soon as we declare an object, the compiler gets the methods and properties related to it. Whereas in late binding, an object is just declared, but the type of objects stored and methods of it are declared later during program execution.

10.  Advantages of early binding and late binding in C#

Ans: Applications run faster, shows high performance and easy to write code without much syntax errors with early binding Late binding support all versions as it decides on runtime and very minimal impact to code with future enhancements.

Hope these C# interview questions and answers will help you crack your very first interview.

Author Bio:


Article by Sirisha Mummidi, a writer from India who loves to write technology articles.

The top interview team