DotNet Interview Questions and Answers
Question - 111 : - Difference between Dispose and Finallize method?
Answer - 111 : - 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.
Question - 112 : - What is encapsulation ?
Answer - 112 : - 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.
Question - 113 : - How can you prevent your class to be inherated further?
Answer - 113 : - By setting Sealed - Key word
public sealed class Planet
{
//code goes here
}
class Moon:Planet
{
//Not allowed as base class is sealed
}
Question - 114 : - What is GUID and why we need to use it and in what condition? How this is created.
Answer - 114 : - 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.
Question - 115 : - Why do you need to serialize.?
Answer - 115 : - 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
Question - 116 : - Describe the advantages of writing a managed code application instead of unmanaged one. What's involved in certain piece of code being managed?
Answer - 116 : - "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
Question - 117 : - What are multicast delegates ? give me an example ?
Answer - 117 : - 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
Question - 118 : - Can a nested object be used in Serialization ?
Answer - 118 : - 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.
Question - 119 : - Difference between int and int32 ?
Answer - 119 : - Both are same. System.Int32 is a .NET class. Int is an alias name for System.Int32.
Question - 120 : - Describe the difference between a Thread and a Process?
Answer - 120 : - 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.