.Net Framework Interview Questions -4

By | May 7, 2014

How to set the debug mode? Debug Mode for ASP.NET applications – To set ASP.NET appplication in debugging mode, edit the application’s web.config and assign the “debug” attribute in < compilation > section to “true” as show below: < configuration >   < system.web >     < compilation defaultLanguage=”vb” debug=”true” / > …. … .. < / configuration > This case-sensitive attribute ‘debug tells ASP.NET to generate symbols for dynamically generated files and enables the debugger to attach to the ASP.NET application. ASP.NET will detect this change automatically, without the need to restart the server. Debug Mode for ASP.NET Webservices – Debugging an XML Web service created with ASP.NET is similar to the debugging an ASP.NET Web application.

What is the property available to check if the page posted or not? The Page_Load event handler in the page checks for IsPostBack property value, to ascertain whether the page is posted. The Page.IsPostBack gets a value indicating whether the page is being loaded in response to the client postback, or it is for the first time. The value of Page.IsPostBack is True, if the page is being loaded in response to the client postback; while its value is False, when the page is loaded for the first time. The Page.IsPostBack property facilitates execution of certain routine in Page_Load, only once (for e.g. in Page load, we need to set default value in controls, when page is loaded for the first time. On post back, we check for true value for IsPostback value and then invoke server-side code to update data).

Which are the abstract classes available under system.xml namespace? The System.XML namespace provides XML related processing ability in .NET framework. XmlReader and XMLWriter are the two abstract classes at the core of .NET Framework XML classes: 1. XmlReader provides a fast, forward-only, read-only cursor for processing an XML document stream. 2. XmlWriter provides an interface for producing XML document streams that conform to the W3C’s XML standards. Both XmlReader and XmlWriter are abstract base classes, which define the functionality that all derived classes must support.

Is it possible to use multipe inheritance in .net? Multiple Inheritance is an ability to inherit from more than one base class i.e.  ability of a class to have more than one superclass, by inheriting from different sources and thus combine separately-defined behaviors in a single class. There are two types of multiple inheritance: multiple type/interface inheritance and multiple implementation inheritance. C# & VB.NET supports only multiple type/interface inheritance, i.e. you can derive an class/interface from multiple interfaces. There is no support for multiple implementation inheritance in .NET. That means a class can only derived from one class.

What are the derived classes from xmlReader and xmlWriter? Both XmlReader and XmlWriter are abstract base classes, which define the functionality that all derived classes must support. There are three concrete implementations of XmlReader:        1.XmlTextReader        2.XmlNodeReader        3.XmlValidatingReader There are two concrete implementations of XmlWriter:        1.XmlTextWriter        2.XmlNodeWriter XmlTextReader and XmlTextWriter support reading data to/from text-based stream, while XmlNodeReader and XmlNodeWriter are designed for working with in-memory DOM tree structure. The custom readers and writers can also be developed to extend the built-in functionality of XmlReader and XmlWriter.

What is managed and unmanaged code? The .NET framework provides several core run-time services to the programs that run within it – for example exception handling and security. For these services to work, the code must provide a minimum level of information to the runtime. i.e., code executing under the control of the CLR is called managed code. For example, any code written in C# or Visual Basic .NET is managed code. Code that runs outside the CLR is referred to as “unmanaged code.” COM components, ActiveX components, and Win32 API functions are examples of unmanaged code.

How you deploy .NET assemblies? One way is simply use xcopy. others are use and the setup projects in .net. and one more way is use of nontuch deployment.

What is Globalizationa and Localization ? Globalization is the process of creating an application that meets the needs of users from multiple cultures. It includes using the correct currency, date and time format, calendar, writing direction, sorting rules, and other issues. Accommodating these cultural differences in an application is called localization.Using classes of System.Globalization namespace, you can set application’s current culture. This can be achieved by using any of the following 3 approaches.       1.      Detect and redirect       2.      Run-time adjustment       3.      Using Satellite assemblies.      

Whate are Resource Files ? How are they used in .NET? 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 informations by localizing application’s resources. You can deploy your resources using satellite assemblies.

Difference between Dispose and Finallize method? Finalize method is used to free the memory used by some unmanaged resources like window handles (HWND). It’s similar to the destructor syntax in C#. The GC calls this method when it founds no more references to the object. But, In some cases we may need release the memory used by the resources explicitely.To release the memory explicitly we need to implement the Dispose method of IDisposable interface.

What is encapsulation ? Encapsulation is the ability to hide the internal workings of an object’s behavior and its data. For instance, let’s say you have a object named Bike and this object has a method named start(). When you create an instance of a Bike object and call its start() method you are not worried about what happens to accomplish this, you just want to make sure the state of the bike is changed to ‘running’ afterwards. This kind of behavior hiding is encapsulation and it makes programming much easier.

How can you prevent your class to be inherated further? By setting Sealed – Key word  public sealed class Planet  {              //code goes here  } class Moon:Planet  {      //Not allowed as base class is sealed  }      

What is GUID and why we need to use it and in what condition? How this is created. A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever  a unique identifier is required. Such an identifier has a very low probability of being duplicated. Visual Studio .NET IDE has a utility under the tools menu to generate GUIDs.

Why do you need to serialize.? We need to serialize the object,if you want to pass object from one  computer/application domain to another.Process of converting complex objects into stream of bytes that can be persisted or  transported.Namespace for serialization is System.Runtime.Serialization.The  ISerializable interface allows you to make any class Serializable..NET framework features 2 serializing method. 1.Binary Serialization 2.XML Serialization

What is inline schema, how does it works? Schemas can be included inside of XML file is called Inline Schemas.This is useful  when it is inconvenient to physically seprate the schema and the XML document.A  schema is an XML document that defines the structure, constraints, data types, and  relationships of the elements that constitute the data contained inside the XML  document or in another XML document.Schema can be an external file which uses the  XSD or XDR extension called external schema. Inline schema can take place even when validation is turned off.

Describe the advantages of writing a managed code application instead of unmanaged one. What’s involved in certain piece of code being managed? “Advantage includes automatic garbage collection,memory management,security,type checking,versioning Managed code is compiled for the .NET run-time environment. It runs in the Common Language Runtime (CLR), which is the heart of the .NET Framework. The CLR provides services such as security, memory management, and cross-language integration. Managed applications written to take advantage of the features of the CLR perform more efficiently and safely, and take better advantage of developers existing expertise in languages that support the .NET Framework. Unmanaged code includes all code written before the .NET Framework was introduced—this includes code written to use COM, native Win32, and Visual Basic 6. Because it does not run inside the .NET environment, unmanaged code cannot make use of any .NET managed facilities.”

What are multicast delegates ? give me an example ? Delegate that can have more than one element in its invocation List.

using System; namespace SampleMultiCastDelegate {   class MultiCast   {     public delegate string strMultiCast(string s);   } } MainClass defines the static methods having same signature as delegate. using System; namespace SampleMultiCastDelegate {     public class MainClass   {     public MainClass()     {      }     public static string Jump(string s)     {       Console.WriteLine(“Jump”);       return String.Empty;     }     public static string Run(string s)     {       Console.WriteLine(“Run”);       return String.Empty;     }     public static string Walk(string s)     {       Console.WriteLine(“Walk”);       return String.Empty;           }   } } The Main class: using System; using System.Threading; namespace SampleMultiCastDelegate {     public class MainMultiCastDelegate   {     public static void Main()     {       MultiCast.strMultiCast  Run,Walk,Jump;       MultiCast.strMultiCast    myDelegate;        ///here mydelegate used the Combine method of System.MulticastDelegate       ///and the delegates combine        myDelegate=(MultiCast.strMultiCast)System.Delegate.Combine(Run,Walk);                      }   } }

Can a nested object be used in Serialization ? Yes. If a class that is to be serialized contains references to objects of other classes, and if those classes have been marked as serializable, then their objects are serialized too.

Difference between int and int32 ? Both are same. System.Int32 is a .NET class. Int is an alias name for System.Int32.

Describe the difference between a Thread and a Process? A Process is an instance of an running application. And a thread is the Execution stream of the Process. A process can have multiple Thread. When a process starts a specific memory area is allocated to it. When there is multiple thread in a process, each thread gets a memory for storing the variables in it and plus they can access to the global variables which is common for all the thread. Eg.A Microsoft Word is a 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.

What is the difference between an EXE and a DLL? You can create an objects of Dll but not of the EXE. Dll is an In-Process Component whereas EXE is an OUt-Process Component. Exe is for single use whereas you can use Dll for multiple use. Exe can be started as standalone where dll cannot be.

What is strong-typing versus weak-typing? Which is preferred? Why? Strong typing implies that the types of variables involved in operations are associated to the variable, checked at compile-time, and require explicit conversion; weak typing implies that they are associated to the value, checked at run-time, and are implicitly converted as required. (Which is preferred is a disputable point, but I personally prefer strong typing because I like my errors to be found as soon as possible.)

What is a PID? How is it useful when troubleshooting a system? PID is the process Id of the application in Windows. Whenever a process starts running in the Windows environment, it is associated with an individual process Id or PID. The PID (Process ID) a unique number for each item on the Process Tab, Image Name list. How do you get the PID to appear? In Task Manger, select the View menu, then select columns and check PID (Process Identifier). In Linux, PID is used to debug a process explicitly. However we cannot do this in a windows environment. Microsoft has launched a SDK called as Microsoft Operations Management (MOM). This uses the PID to find out which dll’s have been loaded by a process in the memory. This is essentially helpful in situations where the Process which has a memory leak is to be traced to a erring dll. Personally I have never used a PID, our Windows debugger does the things required to find out

Leave a Reply