-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLive1.cs
26 lines (25 loc) · 1008 Bytes
/
Live1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
namespace CSharp13;
using System.Runtime.CompilerServices;
using System.Collections.Immutable;
class Live1 : ISample
{
public void Run()
{
Disposer.DisposeAll<StringReader>(new("Hello"), new("World")); //CALL USING params
/* Disposer.DisposeAll<StringReader>([new("Hello"), new("World")]); //FROM C#12 Collection expression
//(pick the "most relevevant" Type!)*/
}
public static class Disposer
{
public static void DisposeAll<T>(params T[] disposables) //OLD params ONLY ARRAY!
where T : IDisposable
{
foreach (IDisposable disposable in disposables) { disposable.Dispose(); }
}
// public static void DisposeAll<T>(IEnumerable<T> disposables) //OTHER methods overload WITH GENERICS<T>
// where T : IDisposable
// {
// foreach (IDisposable disposable in disposables) { disposable.Dispose(); }
// }
}
}