C# Interview Questions and Answers
C# Interview Questions and Answers
In case you’re searching for C# Interview Questions and Answers for Experienced or Freshers, you are at the correct place. Additionally Our C# Online Training is the basic level training to understand the basics of dot net and syntax of Java. In this C# Online Course, the learners will learn about C# syntax, OOPs concept, encapsulation, polymorphism, Interface, inheritance, collections, generics, GAC, assemblies, exception handling, unsafe code, and IO streams. C# is widely used in the arena of web applications, web forms, windows services, web services, console applications, games and windows applications. Here we have collected the generic usage of C# language and framed the interview question and answers to benefit the learners. As C# Online Certification Training is the beginner level course we give more importance to the foundation knowledge and involve the learners in multiple methodologies to make them industry-ready.
There is a parcel of chances from many presumed organizations on the planet. The C# advertise is relied upon to develop to more than $5 billion by 2020, from just $180 million, as per C# industry gauges. In this way, despite everything you have the chance to push forward in your vocation in C# Development. Gangboard offers Advanced C# Interview Questions and answers that assist you in splitting your C# interview and procure dream vocation as C# Developer.
Best C# Interview Questions and Answers
Do you believe that you have the right stuff to be a section in the advancement of future C#, the GangBoard is here to control you to sustain your vocation. Various fortune 1000 organizations around the world are utilizing the innovation of C# to meet the necessities of their customers. C# is being utilized as a part of numerous businesses. To have a great development in C# work, our page furnishes you with nitty-gritty data as C# prospective employee meeting questions and answers. C# Interview Questions and answers are prepared by 10+ years experienced industry experts. C# Interview Questions and answers are very useful to the Fresher or Experienced person who is looking for a new challenging job from the reputed company. Our C# Questions and answers are very simple and have more examples for your better understanding.
Basics of C#
C# is defined as the general object-oriented programming (OOP) language that is used in networking and web development. Dutch software engineer Anders Hejlsberg formed a team to develop C# in January 1999. C# is also known as C Sharp or C-Sharp. These days C# finds application in many software companies and cracking the interview for C# is very important. Below you will find the top 50 questions with answers that are frequently asked in interviews.
Q1) What does C# mean?
Answer: C# is a general object-oriented programming language that is safe and is used for generating Microsoft Intermediate Language by using compiled .Net framework.
Q2) Name the types of comments that are available in C#.
Answer: Following are the types of comments that are available in C#:
- Single line
- Multiple lines
- XML comments
Q3) Can we execute multiple catch blocks?
Answer: No, we cannot execute multiple catch blocks. Once a proper catch code is executed, the control is transferred to the final block such that the code follows the final executed code.
Q4) What is the difference between the following terms: Public, and static?
Answer: Following is the table explaining the difference between public, static and void:
|The variables are accessible anywhere in the application.||The variables are accessible globally without any creation of the class instance.|
Q5) What is the void?
Answer: The void is a type of modifier which states that the variable or method does not return to any value.
Q6) What do you mean by an object?
Answer: An object is defined as an instance of a class that is used for accessing the methods of the class. The “New” keyword is used for the creation of an object. When an object is created in the memory, the memory will have information on methods, variables, and also the behavior of the class that is created.
Q7) What are constructors?
Answer: A constructor is defined as the member function in the class where the class has a similar name as that of the constructor. It is used for constructing the value for the data members while initiating the class.
Q8) What does “Jagged Arrays” mean?
Answer: Jagged arrays refer to the array that has an element of type array. The dimensions and the sizes of the elements are different. An array of arrays is the other name of the jagged array.
Q9) What is the difference between out and ref parameters?
Answer: The difference between out and ref parameters is that out is a parameter that doesn’t need the initialization of argument before passing to the method while the ref is a parameter that needs the initialization of argument before passing to the method.
Q10) What does “serialization” mean?
Answer: Serialization is defined as the process of converting an object into a stream of bytes whereas the reverse process of creating an object from the stream of bytes is known as de-serialization. An object is said to be serializable when it implements ISerialize Interface.
Q11) What is the difference between read-only and constant?
Answer: The difference between read-only and constant is that read-only is used during run time when the value has to be assigned. Constant variables are used during compilation time for declaration and initialization.
Q12) Can “this” be used in a static method?
Answer: No, “this” cannot be used in a static method as static methods are used for either static variables or static methods.
Q13) C# is a managed or unmanaged code?
Answer: C# is a managed code as the common language runtime can be used for compiling C# code to an intermediate language.
Q14) State the difference between direct cast and ctype.
Answer: The difference between direct cast and ctype is that direct cast is used for the conversion of type of an object that requires the run time which is similar to the specified type in the direct cast. Whereas ctype is used for converting the conversion which is defined for the expression and the type.
Q15) How can one use the singleton design pattern in C#?
Answer: The singleton design pattern is used in C# when the class has one instance and the access is provided globally.
Q16) What do C# attributes mean and what is their significance?
Answer: C# attributes are defined as the entities that are provided through declarative tags. Examples of C# attributes are class, method, etc and the information related to attribute can be retrieved during runtime using Reflection.
Q17) State the difference between the “throw” and “throw ex” in .Net.
Answer: The difference between “throw” and “throw ex” is that “throw” is used for preserving original error stack whereas “throw ex” has a throw point through which it can trace the stack. For more accurate, error-free information, the throw is advisable to use.
Q18) In C#.Net, what do indexers mean?
Answer: In C#, indexers are also known as smart arrays. They allow the instances of the class that are to be indexed in a similar as that of the array.
Q19) What does multicast delegate mean?
Answer: Multicast delegate means a delegate having multiple handlers. Every handler is assigned to a method.
Q20) State the difference between is and as operators in C#.
Answer: The difference between is and as an operator in C# is that is the operator is used for checking the compatibility of an object for a given type and returning to the Boolean for the results.Whereas as the operator is used for casting of an object to a type or to a class.
Q21) By using non-default values, how can one create an array?
Answer: By using the command Enumerable. Repeat. a new array can be created in non-default values.
Q22) How can one use nullable types in .Net?
Answer: Nullable types are defined as the types which can either take the normal value or the null value.
Q23) Differentiate between a Struct and a class.
Answer: The difference between a Struct and class is explained in the following table:
|Inheritance is not supported||Inheritance is supported|
|By default, the members are public||By default, the members are private|
|Small isolated models can use struct||Large complex objects can use class|
Q24) What do you mean by object and class?
Answer: An object is defined as an instance of the class. An object is a block of memory that is stored in various forms like variables, array, and a collection. A class is defined as a data-structure that brings all the instances together in a single unit. It is an encapsulation of properties and methods that are used for representing a real-time entity.
Q25) What are the fundamental concepts of OOP?
Answer: OOP stands for Object-Oriented Programming and the following are the fundamental concepts:
- Encapsulation: It is the internal representation of an object which is hidden from the outside view of an object’s definition. Only required information is accessed while the other data are hidden.
- Abstraction: It is defined as the process of identifying critical behavior, eliminating the irrelevant details and data of an object.
- Inheritance: It is defined as the process of creating new classes from another class. This can be achieved by accessing, modifying, and extending the behavior of the objects in their parent class.
- Polymorphism: It is a term used for describing one name in many forms. It can be achieved through the same name but different implementations.
Q26) What do the terms managed and unmanaged code mean?
Answer: Managed code is defined as the code which is executed by CLR where CLR stands for Common Language Runtime. It is said to be managed because, in .Net frame, the unused memory is cleared by using a garbage collector. Unmanaged code is defined as the code which is executed by the application of runtime which does not include the frame of .Net. It is used for taking care of performance operations, memory, and security.
Q27) What is an interface?
Answer: An interface is defined as the class with no implementation. Following are the things that an interface:
- Declaration of method
Q28) Name the classes in C#.
Answer: Following are the different types of classes in C#:
- Partial class: It is denoted by the keyword Partial and is used for allowing members that need to be divided and shared with multiple .cs files.
- Sealed class: It is denoted by the keyword Sealed and is used for members of the sealed class. It cannot be inherited.
- Abstract class: It is denoted by the keyword abstract and it is the only inherited class.
- Static class: It is denoted by the keyword static and it defined as the class which does not allow inheritance.
Q29) What are the steps to be followed for code compilation in C#?
Answer: Following are the four steps that need to be followed for code compilation in C#:
- By using the C# compiler, the source code is compiled into managed code.
- The newly created codes are combined into assemblies.
- CLR (Common Language Runtime) is loaded.
- The execution of assembly is done by CLR.
Q30) What are the different types of serialization?
Answer: Following are the three different types of serialization:
- XML serialization: All the public properties are serialized to the XML document.
- SOAP: Any system that understands SOAP can use this serialization. System.Runtime.Serialization is the place where all the classes reside.
- Binary serialization: It is used for the conversion of any code into binary form.
Q31) What does the XSD file mean?
Answer: The XSD stands for XML Schema Definition. It is used for giving a structure for the XML file. For the conversion of the files to XSD format, Xsd.exe tool is used.
Q32) What does thread pooling mean?
Answer: The collection of threads is known as thread pooling. These threads find application when the tasks are to be performed without disturbing the primary threads. To manage the operations of the threads in the pool, System.Threading.ThreadPool namespace is used.
Q33) What does race condition mean?
Answer: A race condition is defined as a situation in which two threads are accessing the same source and are trying to change at the same time. The prediction of the thread which could come first is difficult.
Q34) What does deadlock mean?
Answer: Deadlock is defined as the situation in which the process does not complete the execution as two or more processes are waiting for the completion of the process. This situation mainly arises during multi-threading.
Q35) Name the different states of a thread.
Answer: Following are the different states of s thread:
- Unstarted: The thread is created
- Running: The execution of the thread starts
- WaitSleepJoin: The thread is asked to sleep, asks other thread to wait and asks the other thread to join
- Suspended: The thread has been suspended
- Aborted: The thread is dead but didn’t change the state
- Stopped: The thread has been stopped
Q36) What are the properties of the thread class?
Answer: Following are the properties of the thread class:
- IsAlive: When the thread is active, it contains the true value
- Name: It is used for setting the name for a thread and also for returning the name of the thread
- Priority: The value is returned to the task set as per operating system
- IsBackground: It is the deciding factor for a thread whether it should be in the background or the foreground
- ThreadState: This explains the state of the thread
Q37) Name a few methods used for handling the multi-threaded operations.
Answer: Following are the few methods that are used for handling the multi-threaded operations:
Q38) What does the term thread mean?
Answer: A thread is defined as a set of instructions that are executed and which enables the program for performing concurrent processing. C# has just one thread and that is by default.
Q39) What does a generic class mean?
Answer: Generic class is used for creating classes or objects that don’t have a specific data type. The data type is assigned during the runtime.
Q40) Name different types of delegates.
Answer: Following are the three types of delegates:
- Single delegate: It is used for calling only a single delegate
- Multicast delegate: This delegate is used for calling multiple methods. For subscribing and unsubscribing + and – operators are used
- Generic delegate: For a delegate to be defined, there is no requirement of instance. The generic delegate is of three types:
Q41) Name a few basic string operations.
Answer: Following are the basic string operations:
- Concatenate: System.String.Concat is the command used
- Modify: It is mainly used for replacing and trimming of the string
- Compare: Two parameters are considered for comparison. Original string and the string to be compared are used. System.StringComparison() is the command used for comparison
- Search: For searching a particular string, Startwith and Endswith methods are used
Q42) What are the properties of an array?
Answer: Following are the properties of an array:
- Length: Used for getting the total number of elements in an array
- IsFixedSize: Used for understanding whether the array has a fixed size or not
- IsReadOnly: Used for understanding whether the array is read-only or not
Q43) What does C# I/O classes mean?
Answer: In C# the various operations related to files such as creating, deleting, opening, closing, etc are done with the help of a namespace called System.IO namespace.
Q44) Name some of the I/O classes.
Answer: Following are the I/O classes of C#:
- File: It is used for manipulating the file
- StreamWriter: The characters in a stream are wrote using StreamWriter
- StreamReader: The characters in a stream are read using StreamReader
- StringWriter: Writing of string buffer is done using StringWriter
- StringReader: Reading of string buffer is done using StringReader
- Path: Path related operations are conducted using path class
Q45) What are the advantages of C#?
Answer: Following are the advantages of C#:
- It is easy to learn.
- It is related to object-orientation.
- It is also related to component orientation.
- It is a part of .Net framework.
Q46) Give examples for types of comments in C#.
Answer: Following are the examples for types of comments in C#:
- Single line comment
- Multiline comments
- XML comments
Q47) Name the IDEs that are provided by Microsoft for the development of C#.
Answer: Following are the IDEs that are provided by Microsoft for the development of C#:
- VCE (Visual Studio Express)
- VS (Visual Studio)
- Visual Web Developer
Q48) What are the types of errors in C#?
Answer: Following are the two types of error in C#:
- Compile-time error
- Run time error
Q49) Name the different types of value types in C#.
Answer: Following are the different types of value in C#:
Q50) Name the different types of reference in C#.
Answer: Following are the different types of reference in C#: