🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.pl.comp.lang.csharp
Article #21840

Re: IDispose oraz interfejsy

#21840
From: Jakub Owczarski
Date: Thu, 18 Nov 2010 12:10
55 lines
2374 bytes
On Nov 17, 12:20 pm, mk <m...@nospam.com> wrote:

> class Program
> {
>     static void Main(string[] args)
>     {
>      string type = KtoraKlaseAktywowac(); //Zwraca "A" albo "B"
>      AQQ aqq;
>
>      switch(type)
>      {
>         case "A":
>          aqq = new A();
>          break;
>         case "B":
>          aqq = new B();
>          break;
>      }
>
>      //using(aqq) // Nie zalecane
>      //{ ... }
>
>      aqq.DoSomething();
>      aqq.Dispose();
>     }
>
> }
>
> Czy jest jakiś sposób żeby w powyższym przykladzie używać klauzuli
> "using"? Jak się powinno zwalniać zasoby w powyższym przypadku?\

Może źle zrozumiałem problem, ale jeżeli chodzi tylko o to, że aqq
jest widoczne poza zasięgiem using, to możesz przecież zrobić takiego
zawijasa:

publc AQQ InstantiateAQQ()
{
     switch(KtoraKlaseAktywowac())
     {
        case "A":
         return new A();
        case "B":
         return new B();
     }
}

...

using(AQQ aqq = InstantiateAQQ())
{
    aqq.DoSomething();
}


pzdr
Technical Details
Message-ID: <6b666618-cdc8-4fdd-bb45-b5e6c20c90b8@p1g2000yqm.googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!nf1.ipartners.pl!ipartners.pl!plix.pl!newsfeed1.plix.pl!goblin2!goblin.stu.neva.ru!aioe.org!feeder.news-service.com!postnews.google.com!p1g2000yqm.googlegroups.com!not-for-mail
References: <4ce3c89e$0$27031$65785112@news.neostrada.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!nf1.ipartners.pl!ipartners.pl!plix.pl!newsfeed1.plix.pl!goblin2!goblin.stu.neva.ru!aioe.org!feeder.news-service.com!postnews.google.com!p1g2000yqm.googlegroups.com!not-for-mail
From: Jakub Owczarski <jakub.owczarski@gmail.com>
Newsgroups: alt.pl.comp.lang.csharp
Subject: Re: IDispose oraz interfejsy
Date: Thu, 18 Nov 2010 04:10:09 -0800 (PST)
Organization: http://groups.google.com
Lines: 58
Message-ID: <6b666618-cdc8-4fdd-bb45-b5e6c20c90b8@p1g2000yqm.googlegroups.com>
References: <4ce3c89e$0$27031$65785112@news.neostrada.pl>
NNTP-Posting-Host: 217.28.177.57
Mime-Version: 1.0
X-Trace: posting.google.com 1290082210 2487 127.0.0.1 (18 Nov 2010 12:10:10 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 18 Nov 2010 12:10:10 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: p1g2000yqm.googlegroups.com; posting-host=217.28.177.57; posting-account=VA26nAoAAACG6Q8p9dqThJrYQdPBTdr3
User-Agent: G2/1.0
X-HTTP-Via: 1.1 skyhqapx02.t.is:3128 (squid/2.6.STABLE23)
X-HTTP-UserAgent: Opera/9.80 (Windows NT 6.1; U; en) Presto/2.6.30 Version/10.63,gzip(gfe)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit