Home Interview Questions and AnswersTechnical Interview Questions and Answers.NETC# CSharp Interview Questions and Answers For Freshers Part-4

c-sharp-img31.How to sort an array in C#?
Using Array.sort(array) function. It sorts the elements in an entire one-dimensional Array using the IComparable implementation of each element of the Array.

32.How to sort an array in C# in descending order?
First sort the array using Array.sort(array) then reverse the same using Array.reverse(array) method.

33.What is a structure in C#?
In C#, a structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating a structure.

Structures are used to represent a record. To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member for your program.

34.What are the differences between a class and structure?
Classes and Structures have the following basic differences:

classes are reference types and structs are value types.

structures do not support inheritance.

structures cannot have default constructor.

35.What is a enumeration in C#?
An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.

C# enumerations are value data type. In other words, enumeration contains its own values and cannot inherit or cannot pass inheritance.

36.What is the default access for a class?
Default access specifier for a class type is internal.

37.What is the default access for a class member?
Default access for the members is private.

38.What is inheritance?
One of the most important concepts in object-oriented programming is inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and speeds up implementation time.

When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.

The idea of inheritance implements the IS-A relationship. For example, mammal IS A animal, dog IS-A mammal hence dog IS-A animal as well, and so on.

39.Is multiple inheritance supported in C#?
No! C# does not support multiple inheritance.

40.How to inherit a class in C#?
A class can be derived from more than one class or interface, which means that it can inherit data and functions from multiple base classes or interfaces. The syntax used in C# for creating derived classes is as follows:

<acess-specifier> class <base_class>
{

}
class <derived_class> : <base_class>
{

}

You may also like

Leave a Comment