Tuesday, 29 December 2015

Simple DotNet Interview Question

1. DotNet Framework. 
2. C#.Net.
3. ASP.Net.
4. ADO.Net. 
5. Project Related Questions. 
6. HR Questions.


                                           1)DotNet Framework

1)What is .Net Framework?

A) NET Framework is an important integral component in .NET software. 
    .NetFramework is a runtime environment,which we can use to run .net applications.

 
2) What is Visual Studio.NET?

 
A) Visual Studio .NET is a Microsoft-integrated development environment (IDE) that can be used for  developing console applications, Windows Applications, Web Applications, Windows Service, Web service.. And so on...

  
3) Difference between .Net Framework and VisualStudio.Net? 

A)   .NET FRAMEWORK.
     
1. It is a run- time environment. we can use to run applications.   
2. It is required for .net developers. .net application end users. 
3. It is a free ware which we have to download from Microsoft Website.

B) VISUAL STUDIO .NET.

1.It is a development environment, which we can use to develop applications.
2. It is required for only .net developers.
3. It is not free way which we can purchase from Microsoft.           

4) What is CLR? 

A) CLR stands for Common Language Runtime, it is .net execution.  
CLR is a common execution engine for all .NET Languages that means every .NET language application has to execute with the help of CLR.  

5) Explain .net application Execution process?

Diagram for .net application execution process :

A)  .Net application Execution process can be divided into 2 step



Step1:

Converting HIGH level language code into MSIL (Microsoft Intermediate Language) with the help of language compilers because .Net execution engine (CLR) can understand only MSIL code.

Step2:

JIT (JUST-IN-TIME) compiler will convert MSIL code to NATIVE code because operating system can understand only NATIVE code or MACHINE code.

6) What is JIT Compiler?

A) JIT (JUST-IN-TIME) Compiler will convert MSIL (Microsoft Intermediate Language) code to Native code because operating system can understand only Native code or machine code.

7) What is CLS?

 1. CLS (Common Language Specifications) is a set of common language standard defined by the Microsoft for all .NET Languages. 
2. Every .NET Language has to follow CLS Standards. 
3. Whenever a Programming Language wants to recognize as .NET Language then it has to follow CLS.


8) What is CTS?

  1. CTS (Common Type System) is a subset of CLS. It is a set of common based data types defined by Microsoft for all .NET Languages. 
2. Every .NET Language has to map their data types with CTS types.



9) What is MSIL Code?

A) Microsoft Intermediate Language (MSIL), is one of the Core component of the  .NET Framework. Any .NET source codes written in any .net supportive language (C#, VB.net etc), when compiled are converted to MSIL. This MSIL, when installed or at the Runtime, gets converted to machine code. The Runtime conversion of MSIL code to the machine code is handled by a component called as the Just In Time (JIT) Compiler.


10) Explain the role of Garbage collector? 


A) In .NET, MEMORY MANAGEMENT is handling by GARBAGE COLLECTOR (GC). GC is an integral part of CLR.  To perform memory Management GC will do 2 duties.
 

1.Allocating the Memory  ->

When new object is created by application garbage collector will allocate memory for that object with in Managed heap.

2. De-Allocating the Memory:-  ->


When an object is not using by the application garbage collector will recognize it as unused object..and garbage collector will destroy unused objects according to generation algorithm.


11) What is Managed Code and Unmanaged Code?  .Net application may contain 2 types of codes.

A) Managed code: 


The code which is taking the help of CLR for execution is called as managed code. 


Example for Managed Code:-

  All .net languages code is managed code. 
VB.Net code, C#.Net code…etc


B) Unmanaged code: -

 
The code which is not taking the help of CLR for execution is called as Unmanaged code.. 


Example for Unmanaged Code:- 

In .net application non .net code is unmanaged code.. 

VB Code, VC++ Code…


Note: -  .net application can contain non .net code.



                                2)C Sharp.Net

1) Why C#.Net? 

A) To develop any type of application by using .NET we require one .NET LANGUAGE to write the business logic of that application.

  
2) Explain about primitive data types? 

A) In C#.NET, according to the type of the data and size of the data, data types are classified into 5 types. 
They are— 
1. Numerical Data types
a) Signed Numerical data types: sbyte, short, int, long 
b) Unsigned Numerical data types;byte, ushort, uint, ulong
 
2.Floating  float, double, decimal 
3.Character related Data types a) Char 
4.Logical Data Types  a) bool 
5. General data Types 
a) string  b) object  These data types are called as PRIMITIVE DATA TYPES.

 
3) What is the MaxValue and MinValue?

  A) MaxValue and MinValue are predefined constants, which are members of every primitive data type structure except bool.  . Using this Constant we can get the MINIMUM value and MAXIMUM value of a data type.

4) Difference between value types and Reference types?

A)Value Type:
1..In value types, data will storing in  STACK MEMORY.
2. Value type variable can contain the actual data. the address of the data.  
3. Structures and Enums are value types .

B)Reference Type:
1. In this, Data will be storing in HEAP MEMORY. 
2.   Reference type variable will contain  the address of the data.
3. Class, interface, delegates come under  this.


5) When we will go for signed data types and when we will go for unsigned data types? 

For Example:- 

When we will go for sbyte?

When we will go for byte?


A) Whenever we want to allow both positive and negative values then we will go for signed data types.  Whenever we want to allow only positive values then we will go for unsigned data types.  Here sbtye is a signed data type and byte is an unsigned data type.


6)What is the output?

  static void Main (string [] args) 
  {  
        Char c='a';
         int j=c; 
        Console.WriteLine (j); 
        Console.ReadLine (); 
   } 
   Output: 97 .


 7)What is the output ? 

 static void Main(string[] args) 
{  
      bool b = true;
      Console.WriteLine(b);
      Console.ReadLine(); 

OUTPUT: True

8) Can we assign null value into value type variable?

 A) No.  but we can assign null values into reference type variable.

  
9)How to assign null value into value type variable?

  A) We have to go for NULLABLE VALUE TYPES. Syntax: <ValueType> ? <VariableName>=NULL;

  
10) When we will declare particular variable as nullable type? 

A) Whenever an input is an optional that means not compulsory then we can declare particular variable as NULLABLE TYPES.


11) What is implicit typed variable when we will go for implicit typed variable? 

Using var keyword we can declare IMPLICIT TYPED VARIABLE.IMPLICIT TYPED VARIABLE can have any data type value and this variable will be converting into particular data type based on the value which is assigning.  Whenever we r unable to expect the type of value which is going to assign.

12)What is the difference between GetType() and typeof()?

A)GetType():
1.It is a operator.
2.. It will return the given data type base type.

B)typeof():
1.It is a method.
2.It will return the given variable base type.

13)What is implicit type casting?

When we will go for explicit type casing? 

A) IMPLICIT TYPE CASTING: - Converting from Smaller size data type to bigger size data type is called as IMPLICIT TYPE CASTING.
 
B)When EXPLICIT TYPE CASTING: - The type casting which is not possible by using implicit type casting then we have to go for EXPLICIT TYPE CASTING.  

14) Difference between Parsing and Converting?

A)Parsing:

1.Using parsing we can convert from only string data type to any other data type except object data type.

B)Converting:
1.Using convert we can convert any data type to any other data type.


15) What is the output? 


static void Main(string[] args) 
{  
    string s1 = "1234";
    string s2 = "1234.5";
    string s3 = "rama";
    string s4 = null; 
    string s5 = "12321321321323232132132332";
    int res; 
    res = int.Parse(s1);
    Console.WriteLine(s1);
    //res = int.Parse(s2);
    //res = int.Parse(s3);
    //res = int.Parse(s4);
    //res = int.Parse(s5);
    Console.ReadLine(); 

OUTPUT: 1234


16) Difference between int.Parse() and Convert.Toint32()?


17) What is Boxing and Unboxing? 

A)BOXING: - It is the process of converting from VALUE type to REFERENCE type.
Ex: converting from int to object.
B)UNBOXING: -It is the process of converting from REFERENCE type to VALUE type.
EX: converting from object to int.  

18) What is the difference between Convert.ToString() and Tostring()? 

A) Convert.ToString() handles NULL values even if variable value become NULL. 
.Tostring() will not handles NULL values it will throw a NULL reference exception error.

19)What is the difference between string and StringBuilder?

    For Example:- 

    static void Main(string[] args) 
   {   
       string s1 = "Hydera";
       Console.WriteLine(s1.GetHashCode());
       s1 = s1 + "bad";
       Console.WriteLine(s1.GetHashCode());
       Console.WriteLine(s1); 
       StringBuilder s2 = new StringBuilder("Hydera");
       Console.WriteLine(s2.GetHashCode());
       s2.Append("Bad");
      Console.WriteLine(s2.GetHashCode());
      Console.ReadLine(); 

  }

20) What is Error, Bug and Defect?  

 Error --> Which comes at the time of development.
Bug --> Which comes at the time of testing. (Pre-Release)
Defect --> Which comes in Production. (Post-Release).

21) Why class and object? 

 CLASS: To achieve ENCAPSULATION, as well as for modularity
OBJECT: To allocate memory for instance variables & to store the address of  instance method.

22) When we will go for instance variable?

   Whenever we required a filed for multiple objects with the different values, then particular variable we will declare as INSTANCE VARAIBLE.

 
23) When we will go for static variable? 

 According to the requirement whenever the value is common for all the objects then particular variable will declared as STATIC. 

24) Difference between instance variable and static variable?  


25) When we will go for readonly?

   Whenever filed is required for every object with the different value, but the value not required change. 
Ex: - EmpNo. 


28) When we will go for static readonly?Difference between static variable and static read only?


 Whenever we want to have common value for every object and value should not be changed forever we will go for static readonly.

29)Difference between constant, static and read-only?

30) When the memory will be allocated for instance variable and static variable? 

 STATIC VARIABLE: - At the time of class is loading, memory will be allocated for static variable. 
INSTANCE VARIABLE: - When the object is created the memory is allocated for instance variable.

31)What is the purpose of constructor and method? 

 Purpose of Constructor: To initialize at the time of creating an object for Instance variable as well as at the time class is loading for static variable. Purpose of Method: To perform operations on state.

32) When we will go for instance method? 

 To perform operations on Instance variables.

33) When will go for static method?

 While defining method if that method is not required to access instance variables we will define particular method as static method.

  
34) If a class is having one static constructor and one instance constructor which constructor will call first?

 First control will execute STATIC constructor because CLASS will load first then OBJECT will create.

  
35) Why static constructor is a parameter less constructor? 

 Static constructor executes at the time of class loading. There is no need to pass values explicitly, so it doesn't have parameters.

  
36) What are the default access modifiers? 

 Default access modifier of class members is private. Default access modifier of a class is internal. 

 
37) What is the super class for all.net classes? 

 OBJECT Class  


38) When object class constructor is calling? 

 When we call instance constructor first it will call object class constructor

.  
39) How constructor calling mechanism will work?

 Constructor is calling from BOTTOM to TOP, but it is executing TOP to BOTTOM.

40) What is this and base? 

A) this: It is a keyword which is representing current class object or instance. Using this we can invoke current class instance members. 
Base: It is a keyword which is representing the super class instance.  Using base keyword we can access super class instance members from derived class or sub class.  


41) How to invoke super class constructor? 

A) base()  

42) How to invoke current class constructor?

  A) this()

43) What is constructor overloading?

  A) Implementing multiple constructors within a single class with different signature (Different no. of parameters or Type of parameters or Order of parameters) is called CONSTRUCTOR OVERLOADING.


44) What is constructor chaining? 

A) Whenever one class constructor is invoking another class constructor which is called as constructor chaining.  For this we can use Base()

  
45) Why Main() is static?

 A) When we run the application CLR has to invoke the Main(). If the Main() is a instance method again it requires object.  To overcome this Main() is defined as static method.

  
46) Main() and static constructor in same class which one will execute first?

 A) STATIC CONSTRUCTOR


 47) What is passing parameter mechanism? How many types?

 A) Passing a value to a function is called as PASSING PARAMETER MECHANISM. 
C#.Net will support passing parameter mechanism in 3 ways.
1. Call by value (or) Pass by value 
2. Call by reference (or) pass by reference 
3. Call by Out (or) pass by out 

 
48) When call by value, call by reference, call by out? 

A) CALL BY VALUE: Whenever we want to pass some value to a function and the modifications are not expecting to reflect back to actual parameter then we will pass it as CALL BY VALUE.

  CALL BY REFERENCE: Whenever we want to pass some value and we are expecting the modifications should be reflected back to actual paramer then we will pass it as CALL BY REFERENCE 

CALL BY OUT: Whenever we don’t want to pass any values but we are expecting back the modifications then we will pass particular parameter as CALL BY OUT.


49) Difference between call by ref and call by out?.  




50) What are oops principles?

A)  1. Encapsulation 
2. Abstraction 
3. Inheritance 
4. Polymorphism

  
51) What is Encapsulation? How can we achieve? 

A) Wrapping STATES and BEHAVIOURS are called as ENCAPSULATION.  Or  Binding VARIABLES and METHODS is called as ENCAPSULATION. By implementing class we can achieve ENCAPSULATION.

  
52) What is abstraction? How can we achieve? 

A) Abstraction means HIDING. Abstractions are 2 types. 
1) data abstraction:-  Hiding unwanted data is called as data abstraction 
2) Method abstraction:-  Invoking required method and hiding unwanted method is called as method abstraction.  With the help of FUNCTION OVERLOADING we can achieve Method ABSTRACTION. 

 
53) What is Inheritance? Types of Inheritance? 

A) Inheriting or deriving members from one class to another class is called as INHERITANCE.  C#.Net will support 5 types of Inheritance. They are 
1. Single Inheritance 
2. Multi-level Inheritance 
3. Multiple Inheritance 
4. Hierarchical Inheritance 
5. Hybrid Inheritance


54) Is C#.Net will support multiple Inheritance? 

A) In C#.NET multiple inheritances is not possible by using classes, which is possible with the help of INTERFACES. 


55) What is sealed class? When we will go for sealed class? 

A) While defining a class, if we have used ―sealed‖ keyword then that class can be called as SEALED CLASS. It cannot be inherited.  Whenever we want to restrict to inherit a class we can go for sealed class. 


56) Difference between static class and sealed class? 


57) Difference between class and structure?


58) Why property?

A) 1.To assign value to a class level variable after creating object to retrieve the value from class level variable individually.  2. Property will provide SECURITY to variable data.  3. Property will provide VALIDATION FACILITY for variable data at the time of Assigning.


59) Difference between constructor and property?


60) What is polymorphism? Types of polymorphism? 

A) Polymorphism means one name many forms. Implementing multiple functionalities with the same name is called POLYMORPHISM. 
It is of 2 types: 
1. Static Polymorphism (or) Compile Time Polymorphism 
2. Dynamic Polymorphism (or) Runtime Polymorphism

61) What is static polymorphism and dynamic polymorphism? 


A) STATIC POLYMORPHISM:  A method which will bind at compile time will execute in runtime is called as static polymorphism or early binding or compile time polymorphism 

B) DYNAMIC POLYMORPHISM:  A method which will bind at compile time will not execute, instead of that a method which will bind at runtime will execute is called as RUNTIME POLYMORPHISM (or) DYNAMIC POLYMORPHISM is nothing but LATE BINDING.

  
62) What is function overloading? When we will go for function overloading? 


A) FUNCTION OVERLOADING: Having multiple methods with the same name but a different no. of arguments or different type of arguments or different order of arguments in a single class or in a combination of base and derived class
 
WHEN: Whenever we want to implement same method with the different functionalities then we have to go for FUNCTION OVERLOADING

   
63) Can we overload static methods? 

A) YES.  

64) What is function overriding? When we will go for function overriding? 

A) FUNCTION OVERRIDING: Having multiple methods with the same name and with the same signature in a combination of base and derived class.
 
WHEN:  Whenever we want to implement a method in multiple classes with the different behavior we can go for method overloading.


65) What is method hiding?

  A) Hiding the SUPER CLASS method within the SUB CLASS by using new keyword as called as METHOD HIDING.

  
66) Can we override static methods? 

A) NO. We cannot define static method as VIRTUAL, OVERRID and ABSTRACT.  Because FUNCTION OVERRIDING is depending on OBJECT or INSTANCE.

67) Difference between function overloading and function overriding?



68) When we will go for abstract class? 

A) Whenever we want to implement some methods in current class and some methods we want declare in current class which we want to implement in future classes then we have to declare that class as abstract class.

69) When we will go for interface? 

A) Whenever we want to declare all the members in current class and want to implement all the members in future classes then we will declare particular class as interface.

  
70) Why we can’t create object for abstract class and interface? 

A) Not required  Because is abstract class is a partial implemented class and interface has no implementation.  Even though these abstract class abstract members and interface members should implement within the derived classes.  Due to that reason we don’t required to create object for abstract class and interface.  We will create an object for derived class and using that object we can access abstract members and interface members.

71) Difference between abstract class and interface?




72) Benefits of oops?

 
A) 1. Reusability 
2. Extensibility 
3. Re-implementation 
4. Modularity 
5. Easy to modify 
6. Easy to implement real world programming 
7. Security 

 
73) What is an exception? 


A) Run time error is nothing but and exception.

  
74) Why exception handling mechanism? 

A) To handle runtime error, when a runtime error is occurred to avoid abnormal termination by displaying user-friendly error messages.

  
75) What code we will write within try, catch and finally blocks? 

A) TRY BLOCK: We have to write the statements which may throw an error.
CATCH BLOCK: We will write the statements to display user friendly messages to the user to give more clarity to the user regarding error. 
FINALLY BLOCK: We will write ERROR FREE code or CLEAN UP code that means the statements which we want to execute irrespective of error occurrence.

  
76) Can we have multiple catch blocks and if yes when we will go for multiple catch blocks? 


A) Yes. Whenever we want to handle multiple errors we have to go for MULTIPLE CATCH BLOCKS.
  
77) What is super class for all .net exception classes? 

A) Exception class
 
78) What is a delegate? Types of delegates? 


A) It is similar like C++ function pointer. Delegate object can hold the address of a function and can invoke a function. Delegates are reference types. 
Delegates are of 2 types 
1. Single cast Delegate and 
2. Multi Cast Delegate

  
79) In C# which is called as type safe function pointers? Why? 


A) In C#.Net, DELEGATES are called as TYPE SAFE FUNCTION POINTERS because Delegate declaration should follow the method declaration which is holding by the delegate object


80) What is language Independency? Is .NET language independent technology? 


A) .Net is supporting for multiple languages. While developing an application by using one .net language we can use another .net language component. 

For example:-  While developing C#.Net application we can use vb.net component. As well as while developing VB.Net application we can use C#.Net component.  Due to that reason we can say that .net is a language independent technology.

 
81) What is an assembly? Types of assemblies? 

A) An Assembly is a unit of code which provides versioning and deployment.

Assemblies are of 2 types:- 
1. Private Assembly 
2. Shared Assembly

82) Difference between dll and exe?


83)Difference between private assembly and shared assembly?


84) What is GAC?

 
A) GAC stands for GLOBAL ASSEMBLY CACHE. IT is a residence for all SHARED ASSEMBLIES. When we install .NET software, GAC folder will create within the following path C:\Windows\Assembly

  
85) What is strong name? How to create strong name? 


A) It is one of the .NET Framework utility, which is representing with a file called sn.exe.  Using this utility we can give a strong name or public key to the given assembly. Strong name or public key will give uniqueness to given assembly among collection of assemblies.


 
86) How to install an assembly into GAC? 


A)  It is represented with a file called GACutil.exe. Using this utility we can install an assembly into GAC folder  Syntax:- D:\\gacutil – i <assemblyname.dll> (Press enter) Example:- D:\\gacutil – i myassembly.dll (Press enter)  Here ―i‖ stands for INSTALLING  The above command will install myassembly.dll into GAC folder.

  
87) What signing assembly? 


A) Informing about created strong name to the assembly is nothing but signing the assembly. 

 
88) What is satellite assembly?


  A) An assembly which we can use to develop multi lingual  applications in .net.  


89) What are Multilingual applications? 


A) An application that supports for more than one human readable language is known as multilingual application. 

 
90) What is Reflection? 


A) Reflection is used to get the information about an assembly programmatically by writing some code.  

  
91) How to implement Reflection in .net? 

A) System.Reflection  System.Type  


92) What are smart arrays in C#.Net? 

A) In C#.Net, INDEXERS are called as SMART ARRAYS because accessing array with the help of indexers will be faster. 
GAC UTILITY:
 
93) What is enum? What is the default data type of enum? 
A) Enum is a value type. It is a collection of constants that means it is a collection of string constants which are representing collection of integer constants.  Int is the default data type of enum.

 
94) Why generics? 

A) Generics allow us to define type-safe data structures, without committing to actual data types. It means it allows the programmer to decide the type of parameter in RUNTIME or CONSUMPTION TIME.

  
95) What we are achieving by using generics? 

A)  We can avoid function overloading in some level.  


96) Can we create normal object for generic class? 

A) NO. We CANNOT create a normal object for Generic class.  


97) Can we pass 2 different type values to generic function? 

A) YES.  HOW : 
Class myclass 
Internal static void print <T, K> (Ta, Kb) 

Class program 
Void Main () 
Myclass.print<int, string> (10,‖sathya‖);
Console.ReadLine (); 

}
   
98) How many types of collections? 

A) Collections are of 2 types: 
1. Normal Collection  
2. Generic Collection 

 
99) What is dictionary? 

A) 1.The Dictionary class is a generic class and can store any data types. 
2. It is a collection of Pairs. 
3. Each pair will have 2 elements: 1. Key value and 2.Item Value. 
4. Every item should be represented with one unique key value.

  
100) How to add summary to a method? 

A) If we want to add a method comment you can just place your cursor on an empty line above one of your method and insert 3 slashes which will insert a comment block for you to fill out.

  
101) Can we call message box with in console application. 

A) Yes. 
1. Start a new project - File -> New Project -> Console Application -> OK. 
2. On Solution Explorer - right click on References and click Add Reference. 
3. Scroll down the list until you find "System.Windows.Forms", click it and then click OK 
4. Now under all the using _____’s add this to the code window:  Using System.Windows.Forms; 
5. Now go to the main function MessageBox.Show ("Hello World"); 
6. Now go to Debug -> Start without Debugging.

 
102) what is partial class? Why partial class? 

A) 1. While defining a class, if we have used partial keyword which can be called as PARTIAL CLASS. 
2. Partial class will split into multiple class files but the class name will be same but class files names should be differ. 
WHY: According to the requirement, whenever multiple resources wants to work on single class then we can declare particular class as a PARTIAL CLASS. 
Ex:-  In asp.net  Webform1 is a partial class 
1) Webform1.aspx:- Here we will write the business logic 
2) Webform1.aspx.desgigner.cs:- Here we will write the designing logic.  


103) what is a thread? 

A) Thread is an independent execution path, it able to run simultaneously with other execution paths. 

 
104) what is the base class library for threading? 

A) System.Threading  


105) How to create thread? 

A) Whenever we want to create a thread, we have to create an object for thread pre-defined class.  Thread thr1=new Thread (); 


106) How to invoke a thread?

A) Using thr1.Start (); 
Start(): It is a pre-defined member method of thread class. Using this method we can invoke or start a thread. 


107) What is threadstart()? 


A) 1. Threadstart() is a pre-defined delegate, which is a part of System.Threading base class library.  2. We can initialize a method to thread with the help of ThreadStart().

 
108) How to send a thread for sleep? 


A) Using Thread.sleep(), we can send a thread for sleep according to the given time. Sleep() method is used to Block the current thread for the specified number of milliseconds. In other words  We can include specific time via thread.sleep() method like as: Thread.Sleep (TimeSpan.FromHours (1)); // sleep for 1 hour Thread.Sleep (1000); // sleep for 1000 milliseconds 


109) How to suspend a thread?

 
A) Using Suspend() we can suspend the targeted thread. When you call Thread.Suspend() on a thread, the system notes that a thread suspension has been requested and allows the thread to execute until it has reached a safe point before actually suspending the thread. A safe point for a thread is a point in its execution at which garbage collection can be performed. 
Once a safe point is reached, the runtime guarantees that the suspended thread will not make any further progress in managed code. A thread executing outside managed code is always safe for garbage collection, and its execution continues until it attempts to resume execution of managed code. 


110) How to call back suspended thread?

 
A) Suspended thread can be called back by using resume().

  
111) How to terminate thread?


A) The Thread.Abort() method is used to start the process of terminating the thread. we are calling this method usually terminates the thread. it raised a System.Threading.ThreadingAbortException in the thread on which it is invoked.

    
112) what is the scope of protected Internal? 


A) If we declare a class or class member access modifier as protected internal which can be accessed by all the classes of CURRENT PROJECT and DERIVED CLASSES of other projects within that application.


 
113) How to call Garabge collector? 

A) Using GC.Collect(); 
The garbage collection class provides the GC.Collect();
which you can use to give your application some direct control over the garbage collector. In general, you should avoid calling any of the collect methods and allow the garbage collector to run independently. 

 
114) Difference between dispose() method and finalize() method? 


A) These are just like any other methods in the class and can be called explicitly but they have a special purpose of cleaning up the object. 

DISPOSE():
In the dispose method we write clean up code for the object. It is important that we freed up all the unmanaged recources in the dispose method like database connection, files etc.  The class implementing dispose method should implement IDisposable interface. A Dispose method should call the GC.SuppressFinalize method for the object it is disposing if the class has desturctor because it has already done the work to clean up the object, then it is not necessary for the garbage collector to call the object's Finalize method.
 
FINALIZE():
A Finalize method acts as a safeguard to clean up resources in the event that your Dispose method is not called. You should only implement a Finalize method to clean up unmanaged resources. You should not implement a Finalize method for managed objects, because the garbage collector cleans up managed resources automatically. Finalize method is called by the GC implicitly therefore you can not call it from your code.
 
Note: In C#, Finalize method cannot be override, so you have to use destructor whose internal implementation will override the Finalize method in MSIL. But in the VB.NET, Finalize method can be override because it does support destructor method. 


















































































































































































































No comments:

Post a Comment