Sunday, August 5, 2007

Coding Issue

Finalize VS Descructor

Finalize and (~) Desctructor is the same

in VB - use Finalize
in C# - u can not use Finalize - must be desctructor (~)

Protected Overrides Sub Finalize()
' Desctructor code to free unmanaged resources
End Sub

~ ClassName(){}

***Desctructor will be called by the garbage collector - if you call

GC.Collect VS GC.SuppressFinalize(Object)
Collect - will run Garbage Collector - which run your Desctructor / finalize
- However I realize It will run before you create another object.

SuppressFinalize - will not run.. your desctructor on the object

Dispose() Vs Descructor

Desctructor - will guarantee run by Garbage Collector - But It may time Lag even you put GC.Collect(); - it Collect.. after you create another object

Dispose - If you need to explicitly clean up without waiting GC...
- But It will not be run by GC - You need to call

or using using Keyword in CS
Using(Object obj = new Object);

Note you call the Dispose method yourself and in Desctructor there is .Dispose as well...
, you should suppress garbage collection on the object once it's gone, as we'll do here.

*** My preference is use Desctructor... to eliminate the risk - and called GC.Collect();

ROUNDING Decimal 2 Digit
Math.round(123.23123 * 100) / 100
ROUNDING Decimal 3 Digit
Math.round(123.23123 * 1000) / 1000

REF and OUT in C#
Ref to use in and out..
out is for out only... you can not parse put input in it... you need to init inside the method...

No comments: