YouTube Icon

Interview Questions.

51 C# Interview Questions and Answers - Mar 04, 2023

fluid

51 C# Interview Questions and Answers

1. What is C#?

C# is one of the excellent programming language for writing and fast improvement of .Net Applications. Syntax of C# could be very just like that of C++. C# is a trendy reason item orientated programming language.

You can discover C# Programming guide right here.

2. What is the ultra-modern model of C#?

The latest version of C# is 7.2 that is with the Visual Studio 2017 model 15.Five.

3. What are new capabilities in model 7.2?

Reference semantics with value types

Non-trailing named arguments

Leading underscores in numeric literals

personal blanketed get entry to modifier

4. Describe approximately Syntax of C#

The syntax of C# is similar to C/C++ and java.

Variables are assigned fee the usage of equal sign(‘=’).

Semicolons ; are used at the give up of each assertion.

Square brackets [ ] are used with arrays.

Curly brackets   are used for grouping statements in features, training or other conditions.

Five. What is the distinction among C# and .Net?

C# is an item-orientated programming language built on .Net framework for the development of programs whilst .Net is an utility improvement framework which includes libraries having a plenty of functionalities,

.Net help many languages like VB.Net, C#.Net, C++.

C# and C#.Net are the equal things.

The .NET libraries can run at the Common Language Runtime(CLR) and hence any language that may run at the CLR also can use the .NET libraries.

You can view detail right here: What is the difference among C# and .NET?

6. What is item?

Object is an example of class that's created dynamically. When we instantiate an object, a block of memory is allotted. The items may be consumer defined, reference or cost kind and inherit immediately or not directly from machine.

Complete description about items: View

7. What is the usage of namespace in C#?

The namespace is a key-word which affords code isolation characteristic. It is used to arrange the numerous objects.

Namespace Namespace_first

    magnificence Class_first  

    interface Interface_name  

    struct Struct_name  

    enum Enum_name  a, b 

    delegate void Delegate_name(int i);

    namespace Namespace_name.Nested

    

        elegance Class_second  

    

eight. What is the usage of key-word ?

Using directives are used to import the namespaces, for instance

the use of System;

the use of System.IO;

the use of WinButton = WinForms::Button;

Using statements This can most effective be used with types that implement IDisposable, and is syntactic sugar for a attempt/in the end block which calls Dispose within the finally block. This is used to simplify resource management. (stackoverflow)

the usage of (Stream enter = File.OpenRead(filename))

    ...

Nine. What is boxing and unboxing?

Boxing: In C# boxing is implicit. It is conversion of value type object into cost of corresponding reference type.

Unboxing: Unlike boxing, unboxing requires specific solid kind. It is a conversion of price of reference type into cost of a fee kind.

Example

int var = 42;         // Value type.

Item obj = var;     // var is boxed into obj.

Int var2 = (int)obj;  // Unboxed back into price kind.

10. What is controlled code and unmanaged code?

Managed code: This sort of code executes below the Common Language Runtime virtual machine. The languages that are written in .Net Framework are controlled codes.

Unmanaged code: Such codes are advanced out of doors the .Net Framework and are called unmanaged codes. The utility that do not run beneath Common Language Runtime are referred to as unamanged codes.

Eleven. What are the homes in C#?

Properties in C#.Internet provide a right mechanism of read, write or compute the values of personal fields. Property is a go back kind function which has one or no parameter. Accessors are used to get admission to and assign the values to personal fields.

There are three kinds of residences i.E. Read/Write, ReadOnly, WriteOnly.

12. What are the accessors?

These are used to limit the accessibility of belongings. With the help of get accessor we access the values of private fields even as with the set accessor, we are able to assign fee to non-public fields.

13. What is digital feature in C#?

Virtual functions are used while we implement a described feature in inherited elegance. These features are carried out in a different way in one of a kind inherited lessons.

14. Operator overloading in C#

In operator overloading special keyword operator is used following by way of image for operator being defined. Like other capabilities overloaded operator has go back kind and parameters.

Built-in operators are overloaded in C#. The programmer has additionally option of overloading person defined sorts.

15. What is enum in C#?

Enum key-word is used to declare enumeration. It is primitive user defined facts type that includes named constants known as enumerator listing.

Enum week_days Mon, Tue, Wed, Thu, Fri, Sat, Sun;

The default form of enum is int, but, enum sorts can be byte, sbyte, brief, ushort, uint, lengthy or ulong. The underlying kind specify how a lot garage is allocated to each enumerator. An enumerator can't include white area in its name.

Sixteen. What is early binding?

Early binding is manner of linking a characteristic with the item throughout compile time. This process is likewise referred to as pointing out binding.

17. How to pass parameters to a characteristic in C#?

You can pass parameters to a function or method through using following three methods.

By Value: You can pass parameters via value. In this way new garage area is created in memory for price parameter.

By Reference: To skip parameter by means of reference ref key-word is used. In this type feature accesses the memory vicinity of argument and passes it to characteristic.

Output Parameter: In this kind out key-word is used. It permits the characteristic to return two values. It is similar to passing parameter by reference except that information is transferred out of the feature.

18. What are nullable kinds in C#?

Nullable facts sorts include defined information kind for null, in addition to their normal values. These are used to combine C# to paintings with cost kinds, and databases that frequently use null values. Following syntax is used to claim a nullable type in C#:

?  = null;

19. What is the distinction among ref and out key phrases?

Ref key-word is used to signify the parameter is surpassed with the aid of reference whilst out keyword is just like ref keyword besides that ref calls for variable be initialized before it's far surpassed.

20. What is difference among struct and a category in C#?

Struct : struct is used to create structure value kind to represent a file. These play similar position as instructions. Struct are fee type whilst lessons are reference kind. Since struct are price kind, therefore, these are allotted and deallocated on the stack or inline.

Magnificence : Class is reference kind and is allocated and deallocated at the heap and rubbish accumulated and tends to devour more assets. In case of boxing and unboxing, a value kind can get boxed while it is solid to a reference type as packing containers are gadgets allocated to the heap and deallocated thru rubbish series. Too an awful lot boxing and unboxing of a cost can negatively effect the overall performance. Reference types which include training are favored in above state of affairs.

21. What is polymorphism and how polymorphism is applied in C#?

The word polymorphism approach “many-formed”. It is the capability to represent the equal programming interface for one-of-a-kind underlying bureaucracy. However, the concept of polymorphism is identical in exclusive programming languages but the implementation differs.

In C# polymorphism can be

Static polymorphism

Dynamic polymorphism

22. What is dependency injection?

Dependency injection is a mechanism used to decouple tightly connected training. In this way direct dependency of instructions upon each is reduced. To gain dependency injection, following methods are used:

Constructor dependency

Property dependency

Method dependency

23. What is the difference between public, static and void?

Public: The public declared variables may be accessed in the whilst application.

Static: Static declared variables are globally on hand with out creating an instance of the class.

Void: Void is a kind modifier that shows that method does not go back any price.

24. What are constructors in C#?

A constructor is a member feature in the magnificence having same name as its magnificence. The constructor is referred to as when object is created.

25. What is Jagged Arrays?

Jagged array is also called array of array. It has elements of type array, therefore, called jagged array. The elements may be of different dimensions and sizes.

26. What is the lock statement in C#?

Lock assertion prevents one thread to go into in critical segment whilst another thread is already in crucial segment. If every other thread attempts to enter a locked-code, it will have to wait, block till object is released.

27. What is serialization?

Serialization is the method of changing item right into a circulate of bytes. After conversion, we can shipping an item via network.

28. What is the difference among dispose and finalize variables in C#?

Dispose: It uses “IDisposable” interface and will unfastened up both managed and unmanaged codes.

Finalize: It is known as via rubbish collector and cannot be called from code. Unlike Dispose technique which is called explicitly, it's miles known as internally.

29. What is the distinction between “throw ex” and “throw” strategies in C#?

“throw ex” In this situation stack trace of exception will get replaced with a stack trace starting at re-throw factor.

“throw” It preserves authentic mistakes stack information.

30. What is the difference between interface and abstract?

Interface: It includes only signatures of techniques, homes, indexers or events. A elegance which implements interface need to also enforce individuals of interface that are specified in interface definition.

Abstract: Abstract modifier suggest the component being changed has incomplete implementation. This modifier can be sued with classes, strategies, houses, indexers and activities. Its use suggests in a class suggests that class is supposed simplest to be case elegance of other training.

31. What is upcasting?

In upcasting operation, base elegance reference is created from a subclass reference.

(subclass -> superclass) (i.E. Teacher -> Student)

32. What is downcasting?

It is contrary to upcasting. In downcasting operation subclass reference is produced from base magnificence reference

(superclass -> subclass) (i.E. Student -> Teacher)

33. What is % operator?

It is called modulus operator. It computes remainder after division of first operand by using the second one operand.

34. What is the difference among “wreck” declaration and “hold” declaration in C#?

Break Statement: Break statements go out the program from particular loop, condition or switch case on meeting a sure condition.

Continue Statement: When a application reveals keep statement, it executes all the statements uptil retain announcement again, with out execution of statements after preserve announcement.

35. What are the name of exceptions in C#?

ArgumentNullException

IndexOutOfRangeException

NullReferenceException

InvalidOperationException

DivideByZeroException

36. What is async modifier in C#?

If async modifier is used in a technique or expression, it specifies that the technique or expression is asynchronous.

37. What is extern modifier in C#?

The extern modifier is used to declare a way that's applied externally.

38. What is sealed modifier?

The sealed modifier is used to save you other instructions from inheriting from it.

39. What is unsafe modifier in C#?

The dangerous modifer shows the risky context, required for any operation including hints.

40. Describe “base” key-word.

The base keyword is used for getting access to participants of base class from inside the derived class.

41. Describe “this” keyword.

This key-word refers to current instance of a category. It is also used to skip object as a parameter  to different technique.

42. Can we inherit multiple interfaces?

Yes you could inherit more than one interfaces in C#.

43. What is object pool in C#?

It is used for monitoring objects being used in code. It reduces object creation overhead.

Forty four. What is series?

A series is stated to be a container of times of other training. For this, the classes put into effect ICollection interface.

Forty five. What is reflection?

It is used to get metadata and assemblies of an object at run time.

Forty six. What are wide variety of training in .Net DLL

One .Net DLL can include limitless variety of lessons.

Forty seven. Describe approximately take place.

Manifest is the metadata which describes assemblies.

48. How many styles of constructors are there in C#?

Following are the five forms of constructors

Default contructor

Private constructor

Static constructor

Instance constructor

Parametrized constructor

forty nine. What are generics in C#?

Generics are used to make the code reusable, resultantly decreases code redundancy and performance is multiplied.

50. What is delegate in C#?

Delegates are kind secure pointers used to represent the reference of techniques having return kind and parameters.

51. What are types of delegates?

Following are varieties of delegates.

Single Delegate

Multicast Delegate

Generic Delegate




CFG