C Sharp interview Questions Part 4

C Sharp Interview Questions Part 5

C Sharp – C Sharp Interview Questions Part 5
Can you create a function in C# which can accept varying number of arguments?

By using the params keyword, a method parameter can be specified which takes a variable number of arguments or even no argument.


Can you pass additional type of parameters after using params in function definition?

No! additional parameters are not permitted after the params keyword in a method declaration. Only one params keyword is allowed in a method declaration.


Which class acts as a base class for all arrays in C#?

The Array class is the base class for all the arrays in C#. It is defined in the System namespace. The Array class provides various properties and methods to work with arrays.


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.


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.


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.


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.

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.