+ 1

Idisposable interface

hi to all is here familiar with IDisposable Interface? some small code for understanding it step by step i know destructor of a class but dispose makes me confused

15th Sep 2017, 4:29 PM
muhamad hardaniyan
muhamad hardaniyan - avatar
4 Antworten
+ 1
thanks of your description but when we see interface idisposable it has just one methoth why there use dispose(boolean args) as protected and vitural , if we define dispose then we must also destructure of class?
15th Sep 2017, 7:10 PM
muhamad hardaniyan
muhamad hardaniyan - avatar
0
using System; using System .Collections .Generic; using System .Linq; using System .Text; using System .Threading .Tasks; namespace ConsoleApplication5 { class Program { static void Main ( string [ ] args ) { using ( First_class f1=new First_class ( ) ) { f1 .Name = "trump"; f1 .Dispose ( ); } Console .ReadKey ( ); using ( second_class f2=new second_class ( ) ) { f2 .id = 25; f2 .Name = "obama"; } Console .ReadKey ( ); } } } using System; using System .Collections .Generic; using System .Linq; using System .Text; using System .Threading .Tasks; namespace ConsoleApplication5 { class First_class : IDisposable { private bool _dispoed=false; protected string name; public string Name { get { return name; } set { name = value; } } public First_class ( ) { } public First_class ( string n ) { name = n; } ~First_class ( ) { Console .WriteLine ( "this distructor of first class" ); } public void Dispose ( ) { Dispose ( true ); GC .SuppressFinalize ( this ); } public virtual void Dispose ( bool disposing ) { if ( !_dispoed ) { if ( disposing ) { Console .WriteLine ( "disposing" ); } _dispoed = true; } } } } using System; using System .Collections .Generic; using System .Linq; using System .Text; using System .Threading .Tasks; namespace ConsoleApplication5 { class second_class:First_class { public int id; public override void Dispose ( bool disposing ) { Console .WriteLine ( "second class disposing"); base .Dispose ( disposing ); } ~second_class ( ) { Console .WriteLine ( "second class distructor"); } } } its so easyer example of your what happen in base.dispose() becuas here is not defined GC.suppressfinalize for child and when this happen?
21st Sep 2017, 9:53 PM
muhamad hardaniyan
muhamad hardaniyan - avatar