2018年7月14日土曜日

開発環境

Head First C# ―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Greene (著)、佐藤 嘉一 (監修, 監修)、木下 哲也 (翻訳)、オライリージャパン)の6章(インタフェースと抽象クラス - クラスに約束を守らせる)、自分で考えてみよう(p. 235)を取り組んでみる。

コード

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:App1"
             x:Class="App1.MainPage">
    <StackLayout>

    </StackLayout>
</ContentPage>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace App1
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();

            IWorker[] workers = new IWorker[8];
            workers[0] = new NectarStinger();
            workers[1] = new RoboBee();
            workers[2] = new Worker();
            workers[3] = workers[0] as IWorker;
            workers[5] = null;
            workers[6] = workers[0];

            string result = "1.(0, 3, 6)\n";
            for (int i = 0; i < workers.Length; i++)
            {
                result += i + ": " + (workers[i] is INectorCollector) + "\n";
            }
            DisplayAlert("", result, "cancel");
            result = "2.(0, 3, 6)\n";
            for (int i = 0; i < workers.Length; i++)
            {
                result += i + ": " + (workers[i] is IStingPatrol) + "\n";
            }
            DisplayAlert("", result, "cancel"); Console.WriteLine("1.(0, 3, 6)");
            result = "3.(0, 1, 2, 3, 6)\n";
            for (int i = 0; i < workers.Length; i++)
            {
                result += i + ": " + (workers[i] is IWorker) + "\n";
            }
            DisplayAlert("", result, "cancel");
        }
    }
}

App.xaml

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App1.App">
 <Application.Resources>
    
 </Application.Resources>
</Application>

App.xaml.cs

using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace App1
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            // MainPage = new MainPage();
            MainPage = new NavigationPage(
                new MainPage() { Title = "" });
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}

0 コメント:

コメントを投稿