コード例 #1
0
ファイル: Program.cs プロジェクト: amysimmons/pluralsight
        static void Main(string[] args)
        {
            var newWarehouse = new Warehouse("Warehouse 1", 101);
            var myItem = newWarehouse.FindAndRetunItem(101);
            Console.WriteLine("my new item is " + myItem.Name);

            var myComputer = new Computer();
            myComputer.ID = 102;

            Item mySecondComputer = new Computer();
            mySecondComputer.ID = 103;
            Computer mySecondComputer2 = mySecondComputer as Computer;
            mySecondComputer2.CPUType = "i7";
            string myCPUType = mySecondComputer2.CPUType;
            mySecondComputer2.Name = "Jupiter";

            mySecondComputer2.Purchase();

            Software mySoftware = new Software();
            mySoftware.Name = "Foo";
            mySoftware.ID = 101;
            mySoftware.ISBN = "1234";
            mySoftware.Purchase();

            //Item newItem = Item.GetItem();
            List<Item> myItems = Item.GetItems(20);
            foreach (Item item in myItems)
            {
                Console.WriteLine("New item ID = {0}, name = {1}",
                    item.ID, item.Name);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var newWarehouse = new Warehouse("Warehouse1", 101);
            var myItem = newWarehouse.FindAndReturnItem(101);
            Console.WriteLine("My new item is {0}", myItem.Name);

            // Inheritance Example
            var myComputer = new Computer();
            myComputer.ID = 102;

            Item mySecondComputer = new Computer(); // only get properties from Item
            mySecondComputer.ID = 103;
            Computer mySecondComputer2 = mySecondComputer as Computer; // treat AS Computer, get all Computer properties
            mySecondComputer2.CPUType = "i7";
            string myCPUype = mySecondComputer2.CPUType;
            mySecondComputer2.Name = "Jupiter";
            mySecondComputer2.Purchase();

            Software mySoftware = new Software();
            mySoftware.Name = "Foo Software";
            mySoftware.ID = 101;
            mySoftware.ISBN = "1234";
            mySoftware.Purchase();

            // Static Method
            Item newItem = Item.GetItem();
            Console.WriteLine("New item ID = {0}, name = {1}", newItem.ID, newItem.Name);
        }