まさるblog

越後在住子持ちプログラマー奮闘記 - Author:まさる(高野 将、TAKANO Sho)

目次

Blog 利用状況

ニュース

著書

2010/7発売


Web掲載記事

@IT

.NET開発を始めるVB6プログラマーが知るべき9のこと

CodeZine

実例で学ぶASP.NET Webフォーム業務アプリケーション開発のポイント

第1回 3層データバインドを正しく活用しよう(前編)

ブログパーツ


書庫

日記カテゴリ

コミュニティ

Closureを使ってグローバル変数除去

ネタ元:Life is beautiful: Python Hack : 噛めば噛むほどおいしくなるクロージャの話

 

C#だとこういうことよね。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Hoge.Get());
      Console.WriteLine(Hoge.Get());
    }
  }

  static class Hoge
  {
    private static Func<string> GetInitializer()
    {
      Console.WriteLine("test");

      var val = "hoge";
      Get = () => val;
      return Get;
    }

    public static Func<string> Get = GetInitializer();
  }
}

実行結果はこんな感じ。

image

 

Hogeクラスのpublic staticなFunc<string>のフィールドである「Get」の中身をGetInitializerメソッドですげ変えてます。

ネタ元のPythonのコードに比べると、どうしても型システムの制限でFunc<string>の部分を書かなきゃならんので、多少は冗長に見えます。

 

が、そんなC#ちゃんが大好きなのでした。

投稿日時 : 2009年11月7日 8:08

Feedback

# re: Closureを使ってグローバル変数除去 2009/11/07 8:08 まさる

トラックバック飛ばしておこう。

http://www.typepad.com/services/trackback/6a00d8341c4f9853ef0120a65c9389970b

飛ぶかな?

# re: Closureを使ってグローバル変数除去 2009/11/08 20:28 かずくん

クロージャって、コールバックの一種だから、どっちかといえばdelegateの方がふさわしくない?

staticなdelegateってないんだっけ?

# re: Closureを使ってグローバル変数除去 2009/11/09 5:35 まさる

Func<T>はdelegateですけど、そういうことではない?

# re: Closureを使ってグローバル変数除去 2009/11/09 12:43 かずくん

ごめん、勘違いしてた

# JavaScriptでもClosureを使って(ry 2009/11/10 6:27 まさるblog

JavaScriptでもClosureを使って(ry

# re: Closure????????????? 2015/01/03 22:02 marianet

http://www.survival-forum.com/member.php?u=3683
http://bbs.smilekrub.net/index.php?action=profile;u=39776
http://bbs.pingshu8.com/home.php?mod=space&uid=186190

# re: Closure????????????? 2015/01/04 23:24 doreenet

http://xmch.cc/home.php?mod=space&uid=2758
http://www.94up.com/home.php?mod=space&uid=1570
http://www.999baozang.com/bbs/space-uid-13840.html

# re: Closure????????????? 2015/01/06 6:11 jonaet

http://cq05.com/space-uid-19282.html
http://h.xbmx114.com/home.php?mod=space&uid=223864
http://cehui114.com/home.php?mod=space&uid=951

# re: Closure????????????? 2015/01/06 22:18 scottet

http://bbs.houseqilu.com/home.php?mod=space&uid=99502
http://www.baozcl.com/space-uid-20202.html
http://goldenkings.net/index.php?action=profile;u=13331

# re: Closure????????????? 2015/01/10 6:08 scottot

http://bbs.citxt.com/home.php?mod=space&uid=312237
http://www.yunmen.net.cn/space-uid-3683.html
http://cnaday.com/home.php?mod=space&uid=4111

# re: Closure????????????? 2015/01/11 18:25 KlerPa

http://center.home0796.com/space-uid-545464.html
http://demo.ridingerlake.com/forums/index.php?action=profile;u=1858
http://kos51.com/home.php?mod=space&uid=9684

# re: Closure????????????? 2015/01/15 17:56 ReyMej

http://hondahatersinc.com/index.php?action=profile;u=1632
http://dcsee.net/home.php?mod=space&uid=464690
http://520zq8.com/home.php?mod=space&uid=11080

# re: Closure????????????? 2015/01/16 4:04 DarcyKod

http://bbs.liao1.com/home.php?mod=space&uid=1434232
http://www.lswjsdc007.com/space-uid-1711.html
http://bbs.xitongerdai.com/space-uid-6742.html

# re: Closure????????????? 2015/01/16 13:31 LorriePic

http://www.stareobiekty.musculardog.com/profile.php?mode=viewprofile&u=1911
http://www.xarcmastering.com/forum/profile.php?mode=viewprofile&u=155687
http://bizschool.com.my/forum/member.php?u=721

# re: Closure????????????? 2015/01/22 9:17 MaryPic

http://healthsophie.comunidades.net
http://physicmarcia.comunidades.net
http://medicalclara.comunidades.net

# re: Closure????????????? 2015/01/25 14:13 NessieFes

http://healthellyix.isnotmyreal.name/
http://healthitamarji.isnotmyreal.name/
http://healthavelinessp.isnotmyreal.name/

# re: Closure????????????? 2015/01/25 21:37 SadieRic

http://www.ecvet-team.eu/en/user/password?name=Amanda_ramy
http://nwu.moy.su/index/8-2709
http://atacom.kz/index/8-28103

# re: Closure????????????? 2015/01/26 4:52 VivianGef

http://n0csw.com/user/password?name=Amanda_rib
http://insightmaker.com/user/password?name=Amanda_guivy
http://www.ukk.sk/forum/memberlist.php?mode=viewprofile&u=121021

# re: Closure????????????? 2015/01/26 11:38 LiLyHah

http://gorodtaishet.ru/index/8-4802
http://kino-bar.net/index/8-1882
http://sukosdsc.hu/user/password?name=Amanda_vox

# re: Closure????????????? 2015/01/28 2:22 DarcyFic

http://gdsdzh.com/home.php?mod=space&uid=24509
http://www.huaiansdy.com/bbs/home.php?mod=space&uid=1422
http://www.brettdanko.com/user/password?name=Amanda_atrow

# re: Closure????????????? 2015/01/29 11:55 DarcyHat

http://www.advancedmanufacturing.co.uk/user/password?name=Amanda_tub
http://vivacova.com/community/memberlist.php?mode=viewprofile&u=46013
http://vip-clan.at.ua/index/8-2579

# re: Closure????????????? 2015/01/29 22:11 LessyBoc

http://hzwxwk.com/home.php?mod=space&uid=56611
http://seeyourstory.com.cn/home.php?mod=space&uid=9006
http://poslezavtra24.ru/user/Amanda_Rex/

# re: Closure????????????? 2015/01/29 23:52 AlenSac

http://guojizixun.com/space-uid-432605.html
http://www.473300.com/space-uid-23638.html
http://esserciconta.it/user/password?name=Amanda_Hak

# re: Closure????????????? 2015/01/30 6:03 MelindaNeg

http://healthinformatics.nl/user/password?name=Amanda_dyell
http://sunwind.gpx.idv.tw/dzx/home.php?mod=space&uid=14305
http://xn----7sbfmaihhmc6agc3andc9rzb.xn--p1ai/user/Amanda_caro/

# re: Closure????????????? 2015/01/31 2:09 LillySeb

http://avtomatvorota.at.ua/index/8-1914
http://dev.adiirc.com/users/367
http://www.ravanagahi.ir/user/password?name=Amanda_clew

# re: Closure????????????? 2015/01/31 8:52 AnnaRah

http://forum2.obd2forum.org/profile.php?mode=viewprofile&u=4
http://www.knightly.com.cn/bbs/space-uid-3313.html
http://www.92nj.net/home.php?mod=space&uid=1186741

# re: Closure????????????? 2015/01/31 15:34 AleenDeb

http://cs-kappa.3dn.ru/index/8-8650
http://demonssirius.ucoz.ru/index/8-5680
http://dalmatinchik.ru/user/Amanda_Gix/

# onde comprar pela internet 2018/01/07 10:29 farmacia en linea life

Necesita receta medica http://farmacia-en-linea.life/seroflo.html comprar en valencia.

# Generic online usa 2018/01/08 6:52 how much does treatment cost

best price in australia http://facetradin.com/user/profile/58112 purchase generic.

# Where can I get cheaper 2018/01/08 14:09 Buy over the counter usa

buying from canada http://www.ebayquality.com/user/profile/47293 compare prices for.

# Withdrawal australia 2018/01/09 4:49 online sales australia

purchase online uk http://doubledubs.com/UserProfile/tabid/82/userId/8501346/Default.aspx withdrawal uk.

# generic bestellen den haag 2018/01/10 2:30 Bestellen Pnline

Duitsland den haag, http://onlinemedicijnenbestellen.life/xenical.html , te koop in nederland rotterdam.

# Hvor kan man kj&amp;#248;pe uten resept Tyskland 2018/01/12 7:13 Nettbutikk Apotek Norge

apotek Tyskland Danmark, http://apoteknettbutikknorge.life/fluoxetine.html , kjøpe online Danmark.

# mennyibe ker&amp;#252;l a online 2018/01/12 9:43 GYOGYSZERTAR-ONLINE-HU.life

tabletta online, http://gyogyszertar-online-hu.life/fluoxetine.html - költség árak.

# online online 2018/01/12 15:19 online apotheker zonder recept life

Generic online, http://online-apotheker-zonder-recept.life/nasonex.html , nederland kopen den haag.

# bestille online 2018/01/12 15:41 apotek nettbutikk norge life

Norge, http://apotek-nettbutikk-norge.life/lynoral.html , Hvor kjøpe nettbutikk.

# generische kosten 2018/01/12 21:23 online apotheker nederland

Bestellen belgie prijzen, http://onlineapothekernederland.life/purinethol.html , kopen zonder recept te koop.

# k&amp;#246;pa apoteket usa 2018/01/12 23:01 billige-apotekvarer.life

alternativ till generic, http://apotekvarerpanettet.life/clomid.html , sälja billig.

# Gunstige kj&amp;#248;p 2018/01/12 23:44 apotek norway life

apotek bergen, http://apotek-norway.life/floxin.html , Hvor kan du kjøpe i Oslo.

# apotek Norge pris 2018/01/13 7:13 apotek norway

Oslo pris, http://apoteknorway.life/hydrochlorothiazide.html , kjøpe online København.

# billigare alternativ till g&amp;#246;teborg 2018/01/13 9:14 Apotekvarer Pa Nett

priser Danmark, http://apotekvarerpanettet.life/amantadine.html , köpa apoteket online.

# goedkoop kopen den haag 2018/01/13 10:00 online apotheek zonder recept

Aanbieding rotterdam, http://onlineapotheekzonderrecept.life/fluoxetine.html , prijs apotheek belgie nederland kopen.

# on-line &amp;#225;rfolyam 2018/01/13 14:14 Online Gyogyszertar Hungaria

vény nélkül recept, http://gyogyszertar-online.life/yasmin.html - Eladás ára.

# kj&amp;#248;p generisk pris 2018/01/13 16:09 APOTEK NORGE ONLINE

i Sverige uten resept jeg, http://apotek-norge-online.life/lynoral.html , selge til salg.

# k&amp;#246;pa receptfritt tyskland 2018/01/13 16:55 sverige apotek panatet life

köp billigt pris, http://apotekvarerpanettet.life/ampicillin.html , generisk billigt recept.

# rendel&amp;#233;s 2018/01/14 6:09 Gyogyszertarban Hungaria

Gyógyszer online, http://gyogyszertarban-online.life/abilify.html - online recept.

# p piller og 2018/01/14 9:33 INTERNET APOTEK NORGE

apotek Norge kjøp, http://internetapoteknorge.life/myambutol.html , for bv online.

# k&amp;#246;pa receptfritt tyskland 2018/01/14 10:32 apotekpanatetsverige.life

bestalla göteborg, http://apotekvarerpanettet.life/minomycin.html , i nätet.

# uten resept Sverige pris 2018/01/14 17:49 norge-apotek life

uten resept i Sverige pris, http://norge-apotek.life/coumadin.html , Gunstige Sverige.

# How much does cost uk 2018/01/14 19:23 cheapest pills

buying in europe http://www.andersfray.com/blog/?page_name=feldene over the counter philippines.

# pris pa stockholm 2018/01/14 20:34 apotek-pa-natet-sverige life

apotek säljes, http://apotekvarerpanettet.life/florinef.html , tabletter kostnad.

# Where to get in australia 2018/01/16 5:42 Nora LeDuc

buy new zealand http://www.noraleduc.com/?page_name=actonel price in malaysia.

# se vende sin receta en chile 2018/01/22 5:56 www.gwsisecurity.com

Alguien ha comprado por internet http://www.gwsisecurity.com/fig/data/farmacia/colofac.html vendo barato.

# generico donde comprar 2018/01/22 12:08 www.suponcreative.com

Donde comprar en paraguay http://www.suponcreative.com/clients/gw/image-book/js/farmacia/ivabradine.html comprar en farmacias sin receta.

# precio de las pastillas en farmacias guadalajara 2018/01/22 12:08 HANDLEDESIGNS.COM

Comprar online argentina http://handledesigns.com/img/farmacia/expansia.html comprar online Chile.

# G&amp;#252;nstig kaufen deutschland 2018/01/22 14:27 ASTROLOGY

medikamente osterreich http://www.vedicastrologyservices.com/_fpclass/apotheke/glime-q.html billig per nachnahme.

# comprar sin receta contrareembolso 2018/01/22 18:15 MDAANE.com

Comprar en España paypal http://mdaane.com/images/blogImages/farmacia/netocur.html comprar sin receta en farmacias.

# venta en bogota 2018/01/22 18:15 The High Desert Pinto Horse

Venden el sin receta medica http://highdesertpintohorse.org/machform/data/form_10940/farmacia/ginkan.html generico Portugal.

# pastillas en venezuela 2018/01/23 0:11 harrison1966.com

Precios de en el salvador http://www.harrison1966.com/gallery/farmacia/plasimine.html para comprar precisa de receita.

# Filmtabletten teilen 2018/01/23 5:07 CHRONOVALVE.COM

preiswert bestellen http://chronovalve.com/ezg_data/apotheke/trilipix.html kaufen gegen rechnung.

# como comprar en maracay 2018/01/23 5:36 Internet Business Images

Donde puedo encontrar http://www.ibi-tn.com/restricted/ibishare/farmacia/darzitil.html comprar sin receta en farmacias Madrid.

# venta de por internet en chile 2018/01/23 5:36 DarkAge

Precios en colombia http://darkagemedia.com/DDD/farmacia/zinox.html cuento cuesta la pastilla en Venezuela.

# Generika kaufen per nachnahme 2018/01/23 14:04 APPLE PHOTO

generika ohne rezept kaufen http://snapapplephoto.com/oldsite/images/apotheke/flutinase.html preis mit rezept.

# Online kaufen legal 2018/01/23 14:41 dana x zheng

in normaler apotheke kaufen http://danazheng.com/assets/fonts/apotheke/romep.html Dabigatran preis.

# se necesita receta 2018/01/23 15:47 www.jessica-straus.com

Es fiable comprar por internet http://www.jessica-straus.com/system/expressionengine/cache/farmacia/fintel.html generica comprar.

# Generika rezeptfrei legal 2018/01/23 16:02 Dungeon Training

generika wirkungszeit http://dungeontraining.net/images/thumb/apotheke/colcrys.html online bestellen erfahrungsbericht.

# compra online 2018/01/23 20:39 www.metalnex.com

Sin receta medica en lima http://www.metalnex.com/wp/design/farmacia/aceon.html generico francia.

# Generika online paypal 2018/01/23 23:12 www.swissair111.org

was sind tabletten http://www.swissair111.org/ubb2/apotheke/meriestra.html kaufen paypal.

# como conseguir sin receta barcelona 2018/01/24 2:47 BANGLAUNITED.COM

En farmacias http://www.banglaunited.com/farmacia/difenak.html comprar contrareembolso España.

# Schwarzmarktpreis 2018/01/24 7:37 tepoztlanvacationrentals

online bestellen mit kreditkarte http://tepoztlanvacationrentals.com/llcj/cache/apotheke/cyproheptadine.html generika rezeptfrei paypal bezahlen.

# Prasugrel kosten 2018/01/24 11:15 gocrossroads

tabletten rezeptfrei preisvergleich http://www.gocrossroads.net/oldsite/cgi-bin/bk/active_guestbook_backups/apotheke/meloxidyl.html filmtabletten wechselwirkungen.

# sin receta en argentina 2018/01/24 18:52 greygreen.org

Comprar en andorra sin receta http://www.greygreen.org/scratch/uploads/farmacia/leponex.html venta en guayaquil.

# Online fast shipping 2018/02/14 18:21 generic pharmacies review

Pills for sale australia http://genericpharmacies.review online overnight shipping.

# Buy overnight shipping 2018/02/14 18:44 http://medications-online.men/

how much does treatment cost http://medications-online.men buying in france.

# Is ordering online safe 2018/02/17 5:44 online medications

Where can I get cheap http://onlinemedications.men price chemist warehouse.

# what comes out in a background check questions are asked during 2018/03/27 1:09 background-checking science

Where do I go to get a criminal background check in atlanta, http://background-checking.science/wyandotte-county-court-records-kansas.html king county washington public court records.

# cost for criminal background check gun purchase in colorado 2018/03/27 5:34 affordable background checks

Nationwide background check free, http://affordable-background-checks.science/what-is-included-in-background-check-for-employment-does-fbi-use.html kershaw county south carolina public records.

# verified personal background check myths 2018/03/27 18:58 background-check-website.science

How to get a background check on yourself, http://background-check-website.science/government-criminal-records-riverside-county-ca-free-marriage.html police background check length.

# background check process year rule 2018/03/28 12:12 advance-background-checks

Chicago jail inmates, http://advance-background-checks.science/federal-regulations-requiring-a-nics-background-check.html jackson county kansas city missouri public records.

# certified criminal record how long does it last uk 2018/03/28 22:39 background-check-tenants science

Florida public records property search, http://background-check-tenants.science/run-background-check-california-free-online-criminal-records.html state of iowa public death records.

# online background check free canada 2018/03/29 8:47 accurate background screening science

Tenant background check application form, http://accurate-background-screening.science/watch-background-check-authorization-form-word.html north yorkshire police accident reports.

# employment background check how long with dui 2018/03/29 10:09 check background

Harris county jail houston tx, http://background-check-someone.science/background-check-on-renters-verification-inc-international.html how much does it cost to get a background check.

# background check sites mn 2018/03/29 23:46 check background

Public criminal records louisville ky, http://accurate-background-check.science/accurate-background-check-job-offer-rescinded-after.html university of michigan criminal background check.

# open online background check and employment california 2018/03/30 2:21 check background

Texas public divorce records, http://background-check-solutions.science/greenville-sc-property-tax-office.html where can i get a level 2 background check done.

# research proposal for phd in computer science sample 2018/03/30 19:34 background-check-site.science

Public arrest records riverside ca, http://background-check-site.science/single-background-check-jobs.html court records honolulu hawaii.

# maine public access court records 2018/04/01 19:28 access background checks stream

Ri criminal defendant search, http://access-background-checks.stream how do background checks work uk.

# criminal background check form dui 2018/04/03 19:22 access background checks

Camden county new jersey clerk of courts public records, http://advanced-background-check.science/background-check-definition-free-online.html public police records nevada.

# re: Closure????????????? 2021/08/09 8:13 hydroxychloroquine sulfate 200 mg tab

who makes chloroquine phosphate https://chloroquineorigin.com/# hydrochloroqine

タイトル
名前
Url
コメント