Interview Questions.

Top 100+ Advanced C# Interview Questions And Answers

fluid

Top 100+ Advanced C# Interview Questions And Answers

Question 1. What Is Attribute In C#?

Answer :

An attributes is a declarative tag this is used to convey statistics about the behaviors of diverse factors (instructions, techniques, assemblies, systems, enumerators, and so forth). It's miles get right of entry to at compile time or run-time. Attributes are declare with a square brackets [] that's locations above the elements.

[Obsolete(“Don’t use Old method, please use New method”, true)]

For example keep in mind the bellow elegance. If we call the antique approach it's going to via error message.

Public magnificence myClass

    [Obsolete("Don't use Old method, please use New method", true)]

    public string Old()  return "Old"; 

    public string New()  return "New"; 

myClass omyClass = new myClass();

omyClass.Old();

Question 2. Why Attributes Are Used?

Answer :

In a program the attributes are used for adding metadata, like compiler instruction or different records (feedback, description, and many others).

C#. NET Interview Questions
Question three. What Are The Types Of Attributes?

Answer :

The Microsoft .Net Framework offers  types of attributes: the pre-defined attributes and custom built attributes.

Pre-outline attributes are 3 kinds:

AttributeUsage
Conditional
Obsolete
This marks a software that some entity need to not be used.

Question 4. What Is Custom Attributes?

Answer :

The Microsoft .Net Framework lets in growing custom attributes that can be used to store declarative facts and can be retrieved at run-time.

C#. NET Tutorial
Question 5. What Is Reflection?

Answer :

Reflection is a manner by using which a pc program can screen and alter its own shape and conduct. It is a manner to discover the shape of assemblies at run time (training, assets, methods). Reflection is the capability to discover the records about items, metadata, and application info (assemblies) at run-time. We need to consist of System.Reflection namespace to perform reflections in C#. For example bear in mind the subsequent C# codes, so one can returns some meta statistics’s.

Public class MyClass

    public digital int Add(int numb1, int numb2)

                    

        return numb1 + numb2;

    

    public virtual int Subtract(int numb1, int numb2)

    

        return numb1 - numb2;

    

static void Main(string[] args)

    MyClass oMyClass = new MyClass();

    //Type statistics.

    Type oMyType = oMyClass.GetType();

    //Method records.

MethodInfo oMyMethodInfo = oMyType.GetMethod("Subtract");

Console.WriteLine("nType statistics:" + oMyType.FullName);

 Console.WriteLine("nMethod data:" + oMyMethodInfo.Name);            

Console.Read();

C Interview Questions
Question 6. Why We Need Reflection In C#?

Answer :

Reflections needed whilst we want to determine / look at contents of an assembly. For instance: at Visual Studio editor intelligence, when we type “.” (dot) before any item, it offers us all of the participants of the item. This is viable for Reflection.

Beside this we need reflection for the subsequent purposes:

To view attribute information at run time
To view the structure of assemblies at run time (lessons, sources, methods)
It allows dynamic/late binding to strategies and properties
In serialization, it is used to serialize and de-serialize items
In web service, it's far used to create and eat SOAP messages and also to generate WSDL
Debugging gear can use reflection to take a look at the nation of an object.
Question 7. What Is Dynamic Keyword?

Answer :

The dynamic is a keyword which become introduced in .NET four.Zero. Computer programming languages are two sorts: strongly typed and dynamically typed. In strongly types all sorts assessments are occurred at bring together time, in dynamic types all varieties of checks are came about at run time.

For instance recollect the following code

dynamic x = "c#";

x++;

It will not offer errors at compile time however will offer error at run time.

C Tutorial ASP.NET Interview Questions
Question eight. When To Use Dynamic?

Answer :

The largest sensible use of the dynamic key-word is while we operate on MS Office.

Question nine. What Is The Difference Between Reflection And Dynamic?

Answer :

Both Reflection and dynamic are used to perform on an object at some stage in run time. But they've a few variations:

Dynamic uses mirrored image internally
Reflection can invoke each public and personal individuals of an object. But dynamic can handiest invoke public members of an item
C & Data Structures Interview Questions
Question 10. What Is Serialization?

Answer :

When we need to transport an object thru community then we want to convert the object into a circulation of bytes. Serialization is a method to convert a complex objects into move of bytes for storage (database, report, cache, etc) or switch. Its main cause is to store the country of an object.

De-serialization is the reverse technique of creating an item from a circulation of bytes to their authentic form.

ASP.NET Tutorial
Question eleven. What Are The Types Of Serialization?

Answer :

The kinds of Serializations are given bellow:

1  Binary Serialization
            In this process all the public, private, examine most effective members are serialized and convert into circulate of bytes. This is used when we need a entire conversion of our objects.
2  SOAP Serialization
           In this manner only public participants are converted into SOAP layout. This is utilized in web offerings.
Three  XML Serialization
            In this procedure handiest public individuals are converted into XML. This is a custom serialization. Required namespaces: System.Xml, System.Xml.Serialization.

Windows Presentation Foundation(WPF) Interview Questions
Question 12. Why Serialization And Deserialization?

Answer :

For example recall, we've got a totally complicated object and we need XML layout to show it on HTML page. Then we are able to create a XML record within the disk, writes all the necessary records on the XML report, and use it for the HTML web page. But this is not proper approach for big variety of users. Extra area is needed; absolutely everyone can see the XML report which creates safety problem. We can overcome it via the use of XML serialization.

C#. NET Interview Questions
Question 13. When To Use Serialization?

Answer :

Serialization is used inside the following functions:

To pass an object from on utility to some other
In SOAP based totally web offerings
To switch data thru move systems, go devices
Windows Presentation Foundation(WPF) Tutorial
Question 14. Give Examples Where Serialization Is Used?

Answer :

Serialization is used to store session nation in ASP.NET packages, to duplicate gadgets to the clipboard in Windows Forms. It is also used to pass gadgets from one utility area to some other. Web services uses serialization.

Question 15. What Is Generics?

Answer :

Generics are the maximum effective features introduced in C# 2.Zero. It is a type-secure information structure that allows us to write codes that works for any statistics kinds.

Windows Communication Foundation (WCF) Interview Questions
Question sixteen. What Is A Generic Class?

Answer :

A established magnificence is a special form of magnificence which can handle any sorts of records. We specify the records types for the duration of the item creations of that elegance. It is said with the bracket <>. For example recall the following Comparer class, which has a method that compare two price and returns as Boolean output.

Public class Comparer

    public bool Compare(Unknown t1, Unknown t2)

    

         if (t1.Equals(t2))

      

            go back true;

        

        else

        

            go back fake;

        

    

Comparer oComparerInt = new Comparer();

Console.WriteLine(oComparerInt.Compare(10, 10));

Comparer oComparerStr = new Comparer();

Console.WriteLine(oComparerStr.Compare("jdhsjhds", "10"));

Windows Communication Foundation (WCF) Tutorial
Question 17. Why We Should Use Generics?

Answer :

Generic provides lot of advantages for the duration of programming. We ought to use generics for the following motives:

It lets in creating class, methods which are kind-safe
It is faster. Because it lessen boxing/un-boxing
It boom the code performance
It facilitates to maximize code reuse, and type protection
C and C++ Interview Questions
Question 18. What Is Collections In C#?

Answer :

Sometimes we need to paintings with associated items for facts garage and retrieval. There are  approaches to work with associated items. One is array and any other one is collections. Arrays are maximum useful for growing and working with a fixed variety of strongly-typed objects. Collections are enhancement of array which gives a extra bendy way to work with businesses of items.

The Microsoft .NET framework affords specialised classes for information garage and retrieval. Collections are certainly one of them. Collection is a facts shape that holds information in one of a kind ways. Collections are two types. One is trendy collections, which is discovered beneath System.Collections namespace and every other one is generic collections, that's found beneath System.Collections.Generic namespace.The conventional collections are extra flexible and most well known to paintings with records.

Some usually used collections beneath System.Collections namespace are given bellow:

ArrayList
SortedList
Hashtable
Stack
Queue
BitArray
C Interview Questions
Question 19. What Is Unsafe Code?

Answer :

In order to preserve safety and kind safety, C# does no longer aid pointer generally. But by means of the usage of dangerous keyword we are able to define an unsafe context wherein pointer may be used. The hazardous code or unmanaged code is a code block that makes use of a pointer variable. In the CLR, unsafe code is called unverifiable code. In C#, the unsafe code isn't always dangerous. The CLR does no longer affirm its safety. The CLR will most effective execute the dangerous code if it's miles within a fully depended on assembly. If we use unsafe code, it's miles our own duty to make sure that the code does not introduce protection risks or pointer mistakes.

Question 20. What Are The Properties Of Unsafe Code?

Answer :

Some houses of dangerous codes are given bellow:

We can define Methods, types, and code blocks as risky
In some instances, dangerous code might also boom the software’s overall performance via casting off array bounds tests
Unsafe code is needed so as to name local functions that require hints
Using dangerous code brings safety and balance dangers
In order to bring together dangerous code, the application ought to be compiled with /dangerous
C# OOPS Interview Questions
Question 21. Can Unsafe Code Be Executed In Untrusted Environment?

Answer :

Unsafe code can not be achieved in an un-depended on environment. For example, we can't run risky code without delay from the Internet.

Question 22. How To Compile Unsafe Code?

Answer :

For compiling dangerous code, we ought to specify the /hazardous command-line switch with command-line compiler.

For example: to compile a program named “myClass.Cs” containing risky code the command line command is:

csc /hazardous myClass.Cs

In Visual Studio IDE in the beginning we need to enable use of dangerous code inside the mission houses.

The steps are given bellow:

Open venture houses
Click at the Build tab
Select the option “Allow unsafe code”
Question 23. What Is Pointer?

Answer :

Pointer is a variable that stores the reminiscence address of every other variable. Pointers in C# have the same abilities as in C or C++.

Some examples are given bellow:

int    *i    // pointer of an integer
waft  *f    // pointer to a glide
double *d    // pointer to a double
char   *ch   // pointer to a person
C# Developer Multi Threading Interview Questions
Question 24. Should I Use Unsafe Code In C#?

Answer :

In C#, pointer is truly used and Microsoft disengaged to use it. But there are a few situations that require pointer. We can use pointer if required at our personal threat. Some sonorous are given bellow:

To deal with present structures on disk
Some superior COM or Platform Invoke scenarios that contain pointer
To performance important codes
ASP.NET Interview Questions
Question 25. How Can We Sort The Elements Of The Array In Descending Order ?

Answer :

For This,First we name the Sort () method after which name Reverse() Methods.

Question 26. Can We Store Multiple Data Types In System.Array ?

Answer :

No.

Question 27. What Is The Difference Between The System.Array.Copyto() And System.Array.Clone() ?

Answer :

System.Array.CopyTo()-->It require a destination array to be existed before and it must be capable to maintain all of the factors in the supply array from the index that is certain to duplicate from the supply array.

System.Array.Clone()-->It does now not require the destination array to be existed because it creates a brand new one from scratch.

Note-These each are used as a shallow copy.

C & Data Structures Interview Questions
Question 28. What Is Difference Between String And Stringbuilder ?

Answer :

StringBuilder is extra green than string.

String :- It is Immutable and is living within System Namespace.

StringBuilder:-It is mutable and resides System.Text Namespace.

Question 29. What Is Class Sortedlist Underneath?

Answer :

It is a Hash Table.

Question 30. What Is The .Net Data Type That Allow The Retrieval Of Data By A Unique Key ?

Answer :

Hash Table

Question 31. Is Finally Block Get Executed If The Exception Is Not Occured ?

Answer :

Yes.

Question 32. Can Multiple Catch () Block Get Executed If The Exception Is Not Occured ?

Answer :

No,Once the proper seize code fires off ,the manage is transferred to the sooner or later block(if any),and the something follows the subsequently block.

Question 33. What Is Multicast Delegate ?

Answer :

The Multicast delegate is a delegate that points to and finally fires off numerous strategies.

Windows Presentation Foundation(WPF) Interview Questions
Question 34. What Are The Ways To Deploy An Assembly ?

Answer :

An MSI Installer
A CAB archive
XCopy command
Question 35. What Is The Dll Hell Problem Solved In .Internet ?

Answer :

In .NET, Assembly versioning lets in the software to specify not handiest the library it needs to run ,but additionally the version of the meeting.

Question 36. What Is A Satellite Assembly ?

Answer :

When we write the code, a  multicultural or multilingual application in .NET and want to distribute the middle utility one by one from the localized modules,the localized assemblies that regulate the middle software ,that is recognized  as Satellite assembly.

Windows Communication Foundation (WCF) Interview Questions
Question 37. How Do We Inherit From A Class In C# ?

Answer :

In c#, we use a colon (:) after which the call of the base magnificence.

Question 38. Does C# Support Multiple Inheritance ?

Answer :

No, we use interface for this cause.

Question 39. Are Private Class -label Variables Inherited ?

Answer :

Yes, but it isn't always handy.We normally recognize that they're inherited however no longer reachable.

Question 40. What Is The Implicit Name Of The Parameter That Gets Passed Into Class "set" Method ?

Answer :

Value and it is datatype(it depends whatever variable we are converting).

C and C++ Interview Questions
Question 41. What Is The Top .Internet Class ?

Answer :

System.Object

Question forty two. How Does Method Overloading Different From Overriding ?

Answer :

A method overloading actually involves having a technique with the same call in the elegance. Whereas in approach overriding we can change method behaviour for a derived magnificence.

C# OOPS Interview Questions
Question forty three. Can We Override Private Virtual Method ?

Answer :

No.

Question forty four. Can We Declare The Override Method Static While The Original Method Is Non Static ?

Answer :

No.

Question 45. Can We Prevent My Class From Being Inherited And Becoming A Base Class From The Other Classes ?

Answer :

Yes.

Question 46. What Is An Interface Class ?

Answer :

This is an summary elegance with public abstract techniques , all of which have to be applied within the inherited instructions.

Question forty seven. Can We Inherit Multiple Interfaces ?

Answer :

Yes.

Question 48. Can We Allow Class To Be Inherited ,but Prevent The Method From Being Overridden ?

Answer :

Yes, first create magnificence as public and make it is approach sealed.

Question 49. What Is Signature Used For Overloaded A Method ?

Answer :

Use exceptional information sorts
Use exclusive range of parameters
Use one of a kind order of parameters
Question 50. What Is The Difference Between An Interface And Abstract Class ?

Answer :

In an interface, all strategies need to be summary however in summary class a few techniques may be concrete.In interface No accessibility modifiers are alloweded but in abstract class a accessibility modifier are alloweded.




CFG