Skip to content
created by Aha00aAha00a at 2010-07-26
last modified by Aha00aAha00a at 2015-10-21
revision: 5

C# using

MSDN - using Statement (C# Reference)

축약형일 뿐이다.

class CA : IDisposable
{
    public void DoSomething() { }
    public void Dispose() { }
}

class CB
{
    void Method()
    {
        using (CA a = new CA())
        {
            a.DoSomething()
        }
    }
}

위 코드는 다음과 같이 확장된다.

class CA : IDisposable
{
    public void DoSomething() { }
    public void Dispose() { }
}

class CB
{
    void Method()
    {
        {
            CA a = new CA();
            try
            {
                a.DoSomething()
            }
            finally
            {
                if (a != null)
                    ((IDisposable)a).Dispose();
            }
        }
    }
}

당연히 using 안에 들어가는 녀석은 IDisposable을 구현해야만 한다.

see also C# CDisposable, C# GarbageCollection

-- 2010-07-28

1. See Also

1.2. Similar Pages

Similar pages by cosine similarity. Words after page name are term frequency.

  • 51.07% CSharpDestructor ca(6:3), void(6:1), class(4:2), try(1:1), garbage(1:1), collection(1:1), 뿐이다(1:1), 코드는(1:1), 다음과(1:1), 같이(1:1)
  • 39.29% CSharpCDisposable dispose(3:11), void(6:3), public(4:3), do(4:3), class(4:1), using(4:1), idisposable(3:1), cdisposable(1:3), if(1:2), idisposable을(1:2)

1.3. Adjacent Pages

Control
≤ 32
all
1.0x
1.0x
80
-120
ON
Metrics
Nodes(visible/total)0/0
Links(visible/total)0/0
Avg degree0.00
Depth coverage0
Queue(fetch/graph)0 / 0
Zoom(scale)1.00x
Ctrl/⌘ + Scroll: Zoom
Root 1-hop 2-hop+