Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Sunday, September 16, 2007

Finalize vs Dispose

In my opinion the difference between "Finalize" and "Dispose":

  • Finalize is always called by the GC, so we could never determine when this would happen.
  • Finalize cannot be overriden or called.
  • In order to use Dispose(), the class should impelement the IDisposable interface.
  • Dispose() is the right place for freeing up unmanaged resources like DB connection, handles, etc...
  • Dispose() is called when using the "using" block.

Wednesday, May 2, 2007

Type of Scope Modifiers in C#

  • internal - defines a type, method or data member as public scope in the context of an assembly. The type, method, or data member cannot be accessed from outside the assembly.
  • internal protected - just like the internal scope method however the method or data member has public scope in the subclassed type.
  • private - defines a data member or method that is not accessible outside of the type defining the method or data member.
  • protected - methods and data members are scoped as private however if the method or data member is callable from a subclassed type.
  • public - defines method and data members accessible regardless of the assembly or program scope.