+ 2

How to delete object ?

C# OOP

27th Nov 2016, 9:13 AM
Ferdy Squid
Ferdy Squid - avatar
5 Answers
+ 4
oh oh.... I didn't check it properly. Thought it's a c++
27th Nov 2016, 2:47 PM
Venkatesh(Venki)
Venkatesh(Venki) - avatar
+ 3
delete obj; delete[] array;
27th Nov 2016, 9:35 AM
Venkatesh(Venki)
Venkatesh(Venki) - avatar
+ 2
The delete keyword may be true in C++, though not in C#; no such keyword exists. Dereference the object by doing object_name = null;
27th Nov 2016, 12:50 PM
Cohen Creber
Cohen Creber - avatar
+ 1
thx mate
27th Nov 2016, 3:48 PM
Ferdy Squid
Ferdy Squid - avatar
0
using (MyIDisposableObject obj = new MyIDisposableObject()) { // use the object here } // the object is disposed here Which is functionally equivalent to: MyIDisposableObject obj; try { obj = new MyIDisposableObject(); } finally { if (obj != null) { ((IDisposable)obj).Dispose(); } }
30th Nov 2016, 2:29 PM
Akwin Lopez
Akwin Lopez - avatar