まさるblog

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

目次

Blog 利用状況

ニュース

著書

2010/7発売


Web掲載記事

@IT

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

CodeZine

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

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

ブログパーツ


書庫

日記カテゴリ

コミュニティ

文字列列挙体っぽい挙動をするものbeta

ネタ元:文字列列挙体がほしい

 

適当にでっち上げてみた。

 

using System;

namespace ConsoleApplication1
{
  class StringEnum
  {
    private String value;

    public StringEnum(String value)
    {
      this.value = value;
    }

    public override string ToString()
    {
      return this.value;
    }

    public override int GetHashCode()
    {
      return 0;
    }

    public override bool Equals(object obj)
    {
      if (obj is StringEnum)
      {
        var target = obj as StringEnum;
        return this.value == target.value;
      }
      else
      {
        return false;
      }
    }

    public static bool operator ==(StringEnum a, StringEnum b)
    {
      if (Object.Equals(a, null))
      {
        return Object.Equals(b, null);
      }
      return a.Equals(b);
    }

    public static bool operator !=(StringEnum a, StringEnum b)
    {
      if (Object.Equals(a, null))
      {
        return !Object.Equals(b, null);
      }
      return !a.Equals(b);
    }
  }

  // ISO 5218を元に作成
  class 性別 : StringEnum
  {
    private 性別(String value) : base(value) { }
    public static 性別 男 { get { return new 性別("1"); } }
    public static 性別 女 { get { return new 性別("2"); } }
  }

  class Program
  {
    static void Main(string[] args)
    {
      性別 sex;

      sex = 性別.男;
      Console.WriteLine("男 : {0}", sex);

      sex = 性別.女;
      Console.WriteLine("女 : {0}", sex);

      String value = sex.ToString();
      Console.WriteLine("女 : {0}", value);

      Console.WriteLine("true : {0}", sex == 性別.女);
      Console.WriteLine("false : {0}", sex == 性別.男);

      Console.WriteLine("true : {0}", 性別.男 == 性別.男);
      Console.WriteLine("true : {0}", 性別.女 == 性別.女);

      Console.WriteLine("false : {0}", 性別.男 == 性別.女);
      Console.WriteLine("false : {0}", 性別.女 == 性別.男);

      Console.WriteLine("false : {0}", 性別.男 == null);
      Console.WriteLine("false : {0}", sex == null);

      Console.WriteLine("false : {0}", null == 性別.男);
      Console.WriteLine("false : {0}", null == sex);

      Console.WriteLine("true : {0}", null == null);
    }
  }
}

実行結果

実行結果

投稿日時 : 2010年10月22日 2:05

Feedback

# re: 文字列列挙体っぽい挙動をするものbeta 2010/10/22 2:11 まさる

ちなみに、ちゃんとインテリセンスも利きます。


あ、Equalsメソッドは

public override bool Equals(object obj)
{
 var target = obj as StringEnum;
 if (Object.Equals(target, null)) return false;
 return this.value == target.value;
}

で良かったか。

# re: 文字列列挙体っぽい挙動をするものbeta 2010/10/22 9:06 中博俊

これJavaでのEnumっぽいもの作るときの実装ですね

# 任意の型で列挙体っぽい挙動をするものbeta 2010/10/22 22:18 まさるblog

任意の型で列挙体っぽい挙動をするものbeta

# bzeQfgLFXzD 2014/08/28 6:20 http://crorkz.com/

cibEoF wonderful issues altogether, you just won a emblem new reader. What would you recommend in regards to your publish that you made some days ago? Any sure?

# PDcShanpwcMM 2014/08/29 7:07 http://podle.pl/

excellent issues altogether, you simply won a emblem new reader. What may you suggest in regards to your publish that you made some days ago? Any sure?

# vzXAvKbIwC 2014/09/08 23:02 https://www.youtube.com/watch?v=mSbbytrVLHY

I am typically to blogging and i actually admire your content. The article has really peaks my interest. I'm going to bookmark your web site and preserve checking for brand spanking new information.

# WwPqzKWGfLiWpOAdSY 2014/09/11 7:35 http://theboatonlinestore.es/

you've gotten an important blog here! would you like to make some invite posts on my weblog?

# kNJlFvrakYEccPVmiJ 2014/09/17 6:22 http://theboatonlinestore.es/

I am typically to blogging and i really respect your content. The article has really peaks my interest. I am going to bookmark your web site and maintain checking for brand new information.

# Kjzeq Bam Pkgq Plg Dxivob 2014/12/02 1:10 WilliamOa

persistently during the last 10 years, whilst the People from france wristband continues to be probably the most famous sort of clothing. The most expensive cufflinks actually purchased were some fond of often the soon-to-be Cal . king Edward cullen VIII through his or her after girlfriend Wallis Simpson. These kinds of presented diamonds set in platinum eagle as well as purchased at retail intended forsplendid screen of style and architectural will probably harmonize having any clothing, proper or maybe everyday, the following a vital functionality purely natural with Sue beliefs of simplicity, a cufflink for all events.
http://www.rochet.com/imagge/2014113016552464013.html
http://www.dstreamtech.com/upload/fille/2014113016464376798.html
http://www.dstreamtech.com/upload/fille/2014113016484545486.html
http://www.rochet.com/imagge/201411301656095657.html
http://www.dstreamtech.com/upload/fille/2014113016491388223.html
http://www.rochet.com/imagge/2014113016533481358.html
http://www.rochet.com/imagge/2014113016505638063.html
http://www.dstreamtech.com/upload/fille/2014113016445683790.html
http://www.rochet.com/imagge/2014113016565142720.html
http://www.rochet.com/imagge/2014113016555664023.html
http://www.rochet.com/files/201412111343188322.html
http://www.rochet.com/files/201412111272626181.html
http://www.rochet.com/files/201412111254993274.html
http://www.rochet.com/files/201412111302935133.html
http://www.rochet.com/files/201412111321474076.html
http://www.rochet.com/files/201412111325064984.html
http://www.rochet.com/files/201412111295997150.html
http://www.rochet.com/files/20141211133074725.html
http://www.rochet.com/files/20141211135826831.html
http://www.rochet.com/files/201412111352270466.html
http://www.thelullabylost.com/app/201412114144185279.html
http://www.giantsupercollector.com/pic/201412114182944480.html
http://www.cosmoscorp.com/app/201412114153870191.html
http://www.jamiconsulting.com/pic/201412114184680681.html
http://www.persoftware.com/aps/201412114203831998.html
http://www.srestates.com/app/201412114115945417.html
http://www.persoftware.com/aps/201412114201182177.html
http://www.recoverysouth.com/cs/20141211495222640.html
http://www.ibd-co.com/app/201412114141986801.html
http://www.chfloor.net/pic/201412114171730567.html

# Matnj Tgb Lumb Glt Kqfdbm 2014/12/06 22:45 Donaldliex

regularly during the last ten years, as the People from france cuff has been one of the most renowned style of tee shirt. The more costly cufflinks ever before sold were being manboobs fond of typically the soon-to-be Full Edward cullen VIII by simply his or her in the future better half Wallis Simpson. These kinds of included expensive diamonds mounted in platinum eagle and displayed public sale forlovely present of fashion and anatomist will harmonize having any kind of attire, formal or even casual, the following a significant functionality purely natural with Simon beliefs of ease-of-use, some sort of cufflink for everyone functions.

http://www.exship.com/files/201412315192785988.html
http://www.nashia.org/files/201412315294256217.html
http://www.iverseninn.com/files/201412315263882734.html
http://www.tigerperson.com/files/201412315171092521.html
http://www.quantum.bz/files/201412315312326296.html
http://www.sebnemsenyener.com/files/20141231525370128.html
http://www.ellsworthtreefarm.com/files/201412315122424297.html
http://www.downeastpension.com/files/sitemap.xml
http://www.sebnemsenyener.com/files/20141231525385010.html
http://www.surgi-tech.com/files/201412315223452652.html
http://www.reichardtconstruction.com/acc/201412217412190723.html
http://www.reichardtconstruction.com/acc/201412217413431331.html
http://www.generatorquotes.com/acc/201412217423396282.html
http://www.insuranceappraisals.biz/acc/201412217415224626.html
http://www.strongservicelp.com/acc/20141221745039767.html
http://www.linear-guideways.com/files/201412215483414822.html
http://www.strategictalentgroup.com/files/20141221612693047.html
http://www.rochet.com/files/20141221547528346.html
http://www.rochet.com/files/201412215424817609.html
http://www.rochet.com/files/201412215433679674.html

# Jpski Qbz Hnxq Unz Nnrncm 2014/12/13 10:55 Robertmt

http://www.mountainstreamrvpark.com/jias/20141210232040731.htmlIn He was quoted stating a great lack of ability allowing cina funds to recognise can lead to an actual "massive bubble" because of overinvestmenthttp://www.rjspencerinc.com/jias/20141210232040120.html. Many pupil's preferred, this valuable transporter might be developed reasonable to handle http://www.tina-jenkins.com/jias/20141211021950042.htmltablet pc devices, articles, Orlando Louboutin Low cost together with written text reserve. Chanel Bags Selling http://www.garsondevelopment.com/jias/20141210232040418.htmlAnd also, Gucci Totes Great deals you may rapidly spend an incredible number of significant kinds http://www.collegedigest.com/jias/20141211021950708.htmlrestore their very own prospects your individual. Bringing about the twelve months 1771 he / she supplied oxygen in many choices using heatinghttp://www.hotdogwebs.com/jias/20141211021950466.html rare metal and also mercury carbonates, gold and silver oxides, alkaline nitrates, strychnine chemical p, and in addition black color shaded oxide connected with manganese. http://www.collegedigest.com/jias/20141211020031841.html
http://www.schildlaw.com/jias/20141211020916053.html
http://www.screentechinc.com/jias/20141211022438444.html
http://www.idnelectronics.com/jias/20141211023011567.html
http://www.qualityswitch.com/jias/20141211020734577.html
http://www.jplawfirm.com/jias/20141210234128574.html
http://www.lakesregionwater.com/jias/20141210235754382.html
http://www.tristartst.com/jias/20141210233015518.html
http://www.durochervetclinic.com/jias/20141210231704881.html
http://www.burtonanddavis.com/jias/20141210233711254.html

# hfatlbsibnx ahoizzsyk zrgoeuyf
2014/12/13 19:19 VictorOt

http://www.kannurclassifides.com/cs/20141211110659123.htmlhttp://www.palmbeachgym.net/cs/20141211110659556.htmlhttp://www.financialfreedom4you.com/cs/20141211110659329.html http://www.ncinsurancequote.com/sea/2014121110471432645.htmlhttp://www.theiridiumgroup.com/sea/2014121110471510156.htmlhttp://www.woodburylitchfieldhills.com/sea/2014121110471420313.html http://www.kpmco.com/mase/20141211160252683.htmlhttp://www.dbrine.com/mase/20141211160251269.htmlhttp://www.shedsandswings.com/mase/20141211160252350.html
http://www.magicbrushart.com/cs/20141211110659593.htmlhttp://www.boberator.com/cs/20141211110659223.htmlhttp://www.tjualumni-midwest.org/cs/20141211110654644.html http://www.scnsystemenginc.com/sea/2014121110471384864.htmlhttp://www.praura.biz/sea/2014121110471430798.htmlhttp://www.ncinsurancequote.com/sea/2014121110471653231.html http://www.qualityconsultantsllc.com/mase/20141211160252717.htmlhttp://www.burtonanddavis.com/mase/20141211160252873.htmlhttp://www.icansinc.com/mase/20141211160252607.html
The appropriate signifies regarding buying a few single Ugg footwear will be tohttp://www.bellanovamedspa.com/cs/20141211110700117.html a try to get people on the market from the close up while using time frame, that are commonly organised by a quite a few take care of the actual extra highly http://www.jamesessary.com/cs/20141211110659973.htmlviewed web-sites accurately everywhere all these shoes or boots can often be http://www.whittiertransfer.com/sea/2014121110471606229.htmlunveiled. By looking regarding to get including savings then you definitely usually are alot more liable tohttp://www.lovettellingtonband.com/cs/20141211110659585.html become coming by just a many boots which are the legitimate article as an additional select in their eyes being fakes or copiehttp://www.azultonsupa.com/cs/20141211110659447.htmlhttp://www.brantleye.com/cs/20141211110700770.htmlhttp://www.buildwizards.co.uk/cs/20141211110700346.html http://www.rinaldisdeliofwpb.com/sea/2014121110471626332.htmlhttp://www.totalretailgroup.com/sea/2014121110471623593.htmlhttp://www.park-n-travel.com/sea/2014121110471639908.html.

# BcdMcRXZbMvsqNbdHs 2015/05/03 18:53 horny

Soyfy5 http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com

# gHeAuCoYzxwDMdea 2015/05/19 6:49 Jesus

Will I have to work shifts? http://www.oliver-sinz.de/termine/ erexin v opinie forum AEG’s attorneys, though, scoffed at the calculation, saying that its expert witness had determined that Jackson’s future earnings – had he lived – would be closer to $21 million. Jackson has a checkered history when it came to completing tours, they said.

# qUclaYHXAOSt 2021/07/03 4:51 https://www.blogger.com/profile/060647091882378654

Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further post thanks once again.

# Illikebuisse qruvs 2021/07/04 16:03 pharmaceptica.com

buy cheap sildenafil citrate https://pharmaceptica.com/

# Illikebuisse trzcp 2021/07/04 17:03 pharmaceptica.com

does erectile dysfunction go away https://www.pharmaceptica.com/

# Illikebuisse debqy 2021/07/04 22:38 pharmacepticacom

tadalafil cost walmart https://www.pharmaceptica.com/

# re: ????????????????beta 2021/07/07 17:00 hydroxycloraquine

malaria drug chloroquine https://chloroquineorigin.com/# define hydrochloric

# vliwe ARS NnBG 2021/07/25 7:17 cuRBavNqQQ

money can't buy everything essay https://truthforce.info/essay/essay-help/ib-history-extended-essay-help.html college essay writer math homework help forum

# re: ????????????????beta 2021/08/07 15:57 how long has hydroxychloroquine been used

chloroguine https://chloroquineorigin.com/# hydroxyquine side effects

# Highly energetic blog, I enjoyed that a lot. Will there be a part 2? 2021/09/02 17:30 Highly energetic blog, I enjoyed that a lot. Will

Highly energetic blog, I enjoyed that a lot. Will there be
a part 2?

# Highly energetic blog, I enjoyed that a lot. Will there be a part 2? 2021/09/02 17:31 Highly energetic blog, I enjoyed that a lot. Will

Highly energetic blog, I enjoyed that a lot. Will there be
a part 2?

# Highly energetic blog, I enjoyed that a lot. Will there be a part 2? 2021/09/02 17:32 Highly energetic blog, I enjoyed that a lot. Will

Highly energetic blog, I enjoyed that a lot. Will there be
a part 2?

# Highly energetic blog, I enjoyed that a lot. Will there be a part 2? 2021/09/02 17:33 Highly energetic blog, I enjoyed that a lot. Will

Highly energetic blog, I enjoyed that a lot. Will there be
a part 2?

# Very good article. I am experiencing many of these issues as well.. 2021/09/06 10:20 Very good article. I am experiencing many of these

Very good article. I am experiencing many of
these issues as well..

# Very good article. I am experiencing many of these issues as well.. 2021/09/06 10:21 Very good article. I am experiencing many of these

Very good article. I am experiencing many of
these issues as well..

# Very good article. I am experiencing many of these issues as well.. 2021/09/06 10:22 Very good article. I am experiencing many of these

Very good article. I am experiencing many of
these issues as well..

# Very good article. I am experiencing many of these issues as well.. 2021/09/06 10:23 Very good article. I am experiencing many of these

Very good article. I am experiencing many of
these issues as well..

# You made some really good points there. I checked on the web for more information about the issue and found most individuals will go along with your views on this site. quest bars http://j.mp/3jZgEA2 quest bars 2021/09/11 14:06 You made some really good points there. I checked

You made some really good points there. I checked on the web for more information about the issue and found
most individuals will go along with your views on this site.
quest bars http://j.mp/3jZgEA2 quest bars

# It's a pity you don't have a donate button! I'd certainly donate to this brilliant blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this website with my 2021/09/14 2:15 It's a pity you don't have a donate button! I'd ce

It's a pity you don't have a donate button! I'd certainly donate to this
brilliant blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google account.
I look forward to fresh updates and will talk about this website with my Facebook group.
Talk soon! scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

# It's a pity you don't have a donate button! I'd certainly donate to this brilliant blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this website with my 2021/09/14 2:16 It's a pity you don't have a donate button! I'd ce

It's a pity you don't have a donate button! I'd certainly donate to this
brilliant blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google account.
I look forward to fresh updates and will talk about this website with my Facebook group.
Talk soon! scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

# It's a pity you don't have a donate button! I'd certainly donate to this brilliant blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this website with my 2021/09/14 2:17 It's a pity you don't have a donate button! I'd ce

It's a pity you don't have a donate button! I'd certainly donate to this
brilliant blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google account.
I look forward to fresh updates and will talk about this website with my Facebook group.
Talk soon! scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

# It's a pity you don't have a donate button! I'd certainly donate to this brilliant blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this website with my 2021/09/14 2:18 It's a pity you don't have a donate button! I'd ce

It's a pity you don't have a donate button! I'd certainly donate to this
brilliant blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google account.
I look forward to fresh updates and will talk about this website with my Facebook group.
Talk soon! scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

# An impressive share! I've just forwarded this onto a coworker who had been doing a little research on this. And he in fact ordered me dinner simply because I discovered it for him... lol. So let me reword this.... Thanks for the meal!! But yeah, thanks f 2021/09/14 18:22 An impressive share! I've just forwarded this onto

An impressive share! I've just forwarded this onto a coworker
who had been doing a little research on this. And he in fact ordered me dinner simply because I
discovered it for him... lol. So let me reword this....
Thanks for the meal!! But yeah, thanks for spending some time to discuss this topic
here on your website. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# An impressive share! I've just forwarded this onto a coworker who had been doing a little research on this. And he in fact ordered me dinner simply because I discovered it for him... lol. So let me reword this.... Thanks for the meal!! But yeah, thanks f 2021/09/14 18:23 An impressive share! I've just forwarded this onto

An impressive share! I've just forwarded this onto a coworker
who had been doing a little research on this. And he in fact ordered me dinner simply because I
discovered it for him... lol. So let me reword this....
Thanks for the meal!! But yeah, thanks for spending some time to discuss this topic
here on your website. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# An impressive share! I've just forwarded this onto a coworker who had been doing a little research on this. And he in fact ordered me dinner simply because I discovered it for him... lol. So let me reword this.... Thanks for the meal!! But yeah, thanks f 2021/09/14 18:24 An impressive share! I've just forwarded this onto

An impressive share! I've just forwarded this onto a coworker
who had been doing a little research on this. And he in fact ordered me dinner simply because I
discovered it for him... lol. So let me reword this....
Thanks for the meal!! But yeah, thanks for spending some time to discuss this topic
here on your website. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# An impressive share! I've just forwarded this onto a coworker who had been doing a little research on this. And he in fact ordered me dinner simply because I discovered it for him... lol. So let me reword this.... Thanks for the meal!! But yeah, thanks f 2021/09/14 18:25 An impressive share! I've just forwarded this onto

An impressive share! I've just forwarded this onto a coworker
who had been doing a little research on this. And he in fact ordered me dinner simply because I
discovered it for him... lol. So let me reword this....
Thanks for the meal!! But yeah, thanks for spending some time to discuss this topic
here on your website. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# Hi! Do you know if they make any plugins to help with Search Engine Optimization? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good gains. If you know of any please share. Kudos! https://parttimejobshiredin30minute 2021/10/22 21:27 Hi! Do you know if they make any plugins to help w

Hi! Do you know if they make any plugins to help with
Search Engine Optimization? I'm trying to get my blog to rank for some targeted keywords but
I'm not seeing very good gains. If you know of
any please share. Kudos! https://parttimejobshiredin30minutes.wildapricot.org/ part time jobs hired in 30 minutes

# Hello! I could have sworn I've been to this site before but after browsing through some of the post I realized it's new to me. Anyways, I'm definitely happy I found it and I'll be book-marking and checking back often! 2021/10/25 22:01 Hello! I could have sworn I've been to this site b

Hello! I could have sworn I've been to this site before but after browsing through some of the post I realized
it's new to me. Anyways, I'm definitely happy I found it and I'll be book-marking and checking back often!

# Hello! I could have sworn I've been to this site before but after browsing through some of the post I realized it's new to me. Anyways, I'm definitely happy I found it and I'll be book-marking and checking back often! 2021/10/25 22:02 Hello! I could have sworn I've been to this site b

Hello! I could have sworn I've been to this site before but after browsing through some of the post I realized
it's new to me. Anyways, I'm definitely happy I found it and I'll be book-marking and checking back often!

# 960nocw 2021/11/17 7:27 bahamut1001

http://xuzhoucsw.com/home.php?mod=space&uid=286571&do=profile&from=space

# chloroquine uk buy 2022/12/26 5:29 MorrisReaks

https://www.hydroxychloroquinex.com/ where to buy chloroquine phosphate

タイトル
名前
Url
コメント