0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

列挙体に近い使い方を、文字列で

Posted at

列挙体に近い使い方を、文字列で

自分的にこの使い方がベストヒット

    class CMessage
    {
        public string mes1 = "静岡県";
        public string mes2 = "鹿児島";
        public string mes3 = "北海道";

        public IEnumerable<string> Enumerate()
        {
            // イテレータ (反復子)
            yield return mes1;
            yield return mes2;
            yield return mes3;
        }
    }

使い方

    class Program
    {
        static void Main(string[] args)
        {
            // 個々に表示する  
            Console.WriteLine(CEN_FLG_YN.ARI);
            Console.WriteLine(CEN_FLG_YN.NASHI);

            // 連続表示する
            foreach (string s in CEN_FLG_YN.Enumerate())
            {
                Console.WriteLine(s);
            }

            // New()を使用するタイプ
            CMessage mes = new CMessage(); 
            foreach (string s in mes.Enumerate() )
            {
                Console.WriteLine(s);
            }
        }
    }
0
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?