Tuesday, July 28, 2020

Interview Questions and Answers on .Net Framework C#.Net (Part-2)

Interview Questions and Answers on .Net Framework and C#.Net

Question 40 – What are the Advantages of XML Serialization? 
• Serialization is of XML based. 
• Support for cross-platform programming. 
• Easily readable and editable. 

Question 41 – What is Custom Serialization? 
• In some cases, the default serialization techniques provided by .NET may not be sufficient in real life. • This is when we require implementing custom serialization. 
• It is possible to implement custom serialization in .NET by implementing the ISerializable interface. 
• This interface allows an object to take control of its own serialization and de-serialization process. 
• It gives us a great deal of flexibility in the way we can save and restore objects. 

Question 42 – What is a Namespace? 
• Containers of objects which contain classes, unions, structures, interfaces, enumerators, delegates. 
• Main goal is for creating a hierarchical organization of the program. 
• Developers do not need to worry about the naming conflicts of classes, functions, variables etc. 

Question 43 – What is GUID? 
It is a Short form of Globally Unique Identifier, A unique 128-bit number that is produced by the Windows OS or Windows app to identify a particular component, application, file, database entry, and/or user. 

Question 44 – What is a Formatter? 
• A formatter is used to determine the serialization format for objects. 
• In other words, it is used to control the serialization of an object to and from a stream. 
• They are the objects that are used to encode and serialize data into an appropriate format before they are transmitted over the network. 
• They expose an interface called the IFormatter interface. IFormatter’s significant methods are Serialize and De-serialize which perform the actual serialization and de-serialization. 
• There are two formatter classes provided within .NET, the BinaryFormatter and the SoapFormatter. Both these classes extend the IFormatter interface. 

Question 45 – What is a Binary Formatter? 
The Binary formatter provides support for serialization using binary encoding. The BinaryFormater class is responsible for binary serialization and is used commonly in .NET’s Remoting technology. This class is not appropriate when the data is supposed to be transmitted through a firewall. 

Question 46 – What is SOAP Formatter? 
The SOAP formatter provides formatting that can be used to serialize objects using the SOAP protocol. It is used to create a Soap envelope and it uses an object graph to generate the result. It is responsible for serializing objects into SOAP messages or parsing the SOAP messages and extracting these serialized objects from the SOAP messages. SOAP formatters in .NET are widely used by Web Services. 

Question 47 – What is Reflection? 
• It is a collection of classes which allow u to query assembly (class/object) metadata at runtime. 
• Using reflection we can also create new types and their instances at runtime and invoke methods on these new instances. 
• At runtime, the Reflection mechanism uses the PE file to read information about the assembly. 
• We can dynamically invoke methods using the System.Type.Invokemember 
• We can dynamically create types at runtime using System.Reflection.Emit.TypeBuilder 
• With reflection we can do the below 
• we can dynamically create an instance of a type 
• bind the type to an existing object 
• get the type from an existing object 
• invoke its methods or access its fields and properties 

Question 48 – What are Thread and Process? 
• Threads are basically lightweight processes responsible for multitasking within a single application. 
• The base class used for threading is System.Threading. 
• Threads are implemented when situations in which you want to perform more than one task at a time. • A Process is an instance of a running application. 
• A thread is the Execution stream of the Process. 
• A process can have multiple Threads. 
• Example: A Microsoft Word is an Application. When you open a word file, an instance of the Word starts and a process is allocated to this instance which has one thread. 
• Create Thread – use System.Thread() class and create an instance. 
• Join Thread – use object.Join() to join threads. 
• Suspend Thread – use object.Sleep() to suspend a thread. 
• Kill Thread – use object.Abort() to abort a thread. 

 Question 49 – What are the difference between a DLL and an Exe? 

DLL

EXE

Create an object of dll

Not in exe

Multiple Uses

Single use

Cannot be started as stand alone

Can be started as stand alone


Question 50 – What are Globalization and Localization? 
To implementing a multilingual user interface, you design the user interface to open in the default UI language and offer the option to change to other languages. Globalization is the first step in the process. A globalized application supports localized user interfaces and regional data for all users. Truly global applications should be culture-neutral and language-neutral. A globalized application can correctly accept, process, and display a worldwide assortment of scripts, data formats, and languages. Accommodating these cultural differences in an application is called localization. 

Question 51 – What is a Resource File?
Resource files are the files containing data that is logically deployed with an application. These files can contain data in a number of formats including strings, images and persisted objects. It has the main advantage of If we store data in these files then we don’t need to compile these if the data get changed. In .NET we basically require them storing culture-specific information’s by localizing application’s resources. You can deploy your resources using satellite assemblies. 

Question 52 – What is Code Access Security(CAS)?
CLR allows code to perform only those operations that the code has permission to perform. So CAS is the CLR’s security system that enforces security policies by preventing unauthorized access to protected resources and operations. Using the Code Access Security, you can do the following: 
• Restrict what your code can do 
• Restrict which code can call your code 
• Identify code Code access security consists of the following elements: 
• Permissions – represent access to a protected resource or the ability to perform a protected operation. 
• Permission sets – A permission set is a collection of permissions. 
• Code groups – a logical grouping of code that has a specified condition for membership Evidence 
• Policy – Security policy is the configurable set of rules that the CLR follows when determining the permissions to grant to code. 
• There are four policy levels – Enterprise, Machine, User, and Application Domain, each operating independently from each other. Syntax 
• See CAS objects — Run ‘caspol -lg’ from command line. 
• Add CAS objects — caspol -ag 1.3 -site www.mydomain.com FullTrust 
• Change CAS obj — caspol -cg 1.3 FullTrust 
• Turn Off — caspol -s off 

Question 53 – What is difference between Code Based Security and Role Based Security? 
CAS is the approach of using permissions and permission sets for a given code to run. Example, Admin can disable running executables off the Internet or restrict access to corporate database to only few applications. 
• Role security most of the time involves the code running with the privileges of the current user. This way the code cannot supposedly do more harm than mess up a single user account. 
• Neither is better. It depends on the nature of the application; both code-based and role-based security could be implemented to an extent. 

Question 54 – What is difference between Invoke and Begin Invoke 
• Delegate.Invoke: Executes synchronously, on the same thread. 
• Delegate.BeginInvoke: Executes asynchronously, on a thread pool thread. 
• Control.Invoke: Executes on the UI thread, but calling thread waits for completion before continuing. • Control.BeginInvoke: Executes on the UI thread, and calling thread doesn’t wait for completion. 
• BeginInvoke is asynchronous. When BeginInvoke is called from the UI thread the request will be executed in parallel with the UI thread. Which means it may not execute until after the currently executing method has returned. So in this case the text box will never appear to update because the for loop will not be interrupted, as the calling thread will not wait for this event to be completed before continuing. 
• Alternatively, Invoke is synchronous. The text box will be updated because the calling thread will wait for the call to complete before continuing execution. 

Question 55 – What is the difference between Debug and Trace? 
Tracing is actually the process of collecting information about the program’s execution. Debugging is the process of finding & fixing errors in our program. Tracing is the ability of an application to generate information about its own execution. Trace and Debug work in a similar way, the difference is that tracing from the Debug class only works in builds that have the DEBUG symbol defined, whereas tracing from the Trace class only works in builds that have the TRACE symbol defined. 
• Use System.Diagnostics.Trace.WriteLine for tracing that you want to work in debugging and release builds 
• Use System.Diagnostics.Debug.WriteLine for tracing that you want to work only in debug builds.

 Question 56 – What is a Debug version of code? 
• Preprocessor(Debugging Diagnostic) macro _DEBUG is enabled. 
• More memory size. 
• Support files required. (MFC Dll’s) 
• No Code Optimization 
• Uses MFC Debug Library 
• ASSERT is enabled. 
• Execution takes more time 

Question 57 – What is a Release version of a code? 
• Preprocessor(Debugging Diagnostic) macro NDEBUG is enabled. 
• Less memory size. 
• Support files not required. (MFC Dll’s) 
• Code Optimization 
• Uses MFC Release Library 
• ASSERT is disabled anything inside of ASSERT will not be executed. 
• Execution takes less time 

Question 58 – What is an IDisposable Interface? 
• The primary use of this interface is to release unmanaged resources. The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used. 
• However, it is not possible to predict when garbage collection will occur. 
• Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams. 
• The consumer of an object can call this method when the object is no longer needed. 

Question 59 – What is Finalize block in .net? 
• Finalize() is called by the runtime 
• Is a C# equivalent of destructor, called by Garbage Collector when the object goes out of scope. 
• Implement it when you have unmanaged resources in your code, and want to make sure that these resources are freed when the Garbage collection happens. 
• Finalize() can NOT be overridden or called in C#. 
• Since, Finalize() is called by the Garbage Collector, it is non-deterministic. 

Question 60 – What is Dispose block in .net? 
• Dispose() is called by the user 
• Same purpose as finalize, to free unmanaged resources. However, implement this when you are writing a custom class, that will be used by other users. 
• Overriding Dispose() provides a way for user code to free the unmanaged objects in your custom class. 
• Dispose() has to be implemented in classes implementing IDispose interface. 
• Dispose() method is called explicitly in the code itself.

No comments:

Post a Comment