裏口からのC#実践入門

1-13 ポインタの利用

  • C#のポインタはデメリットの方が多い
  • 99%、ポインタは死ぬまで使わない

1-14 無駄なキャストの多用

キャストをなるべく行わないようにする。
基本的に、自分はList使うかも。

  • 型の誤用は真っ先に訂正すべき

1-15 全部1クラス症候群

CustomerとProductクラス、それを管理するクラスで別で作るべきかな。

using System;
using System.Collections.Generic;

namespace Uraguchi.Scene1
{
    class TenshiCustomer
    {
        private static List<string> customers = new List<string>();

        public static void Add(string customer)
        {
            customers.Add(customer);
        }

        public static void View()
        {
            customers.ForEach(c => Console.WriteLine(c));
        }
    }

    class TenshiProduct
    {
        private static List<string> products = new List<string>();

        public static void Add(string product)
        {
            products.Add(product);
        }

        public static void View()
        {
            products.ForEach(p => Console.WriteLine(p));
        }
    }

    public class Tenshi15
    {
        public static void Run()
        {
            TenshiCustomer.Add("世界スーパー大企業様");
            TenshiCustomer.Add("自家用ジェットリンクス");
            TenshiProduct.Add("インスタントラーメンイチロー");

            TenshiCustomer.View();
            TenshiProduct.View();
        }
    }
}