開発環境
- OS: Windows 10 Pro
- IDE(統合開発環境): Visual Studio Community 2017
Head First C# ―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Greene (著)、佐藤 嘉一 (監修, 監修)、木下 哲也 (翻訳)、オライリージャパン)の4章(型と参照 - 10時です。データがどこにあるかわかりますか?)、自分で考えてみよう(p. 155)を取り組んでみる。
コード
MainPage.xaml
<Page x:Class="App.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid> <Button x:Name="button1" Content="button1" HorizontalAlignment="Center" VerticalAlignment="Center" Click="button1_Click"/> </Grid> </Page>
MainPage.xaml.cs
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; using Windows.UI.Popups; // 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x411 を参照してください namespace App { /// <summary> /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。 /// </summary> public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } private async void button1_Click(object sender, RoutedEventArgs e) { Elephant[] elephants = { new Elephant("リロイド", 100), new Elephant("ルシンダ", 85), new Elephant("ラリー", 105), new Elephant("ルシール", 82), new Elephant("ラース", 110), new Elephant("リンダ", 93), new Elephant("ハンフリー", 113) }; Elephant biggestEars = elephants[0]; for (int i = 1; i < elephants.Length; i++) { if (elephants[i].EarSize > biggestEars.EarSize) { biggestEars = elephants[i]; } int size = i == 1 ? 100 : i == 2 ? 105 : i == 3 ? 105 : i == 4 ? 110 : i == 5 ? 110 : 113; MessageDialog md = new MessageDialog( i + "回目 " + size.ToString() + ": " + (size == biggestEars.EarSize)); await md.ShowAsync(); } } } public class Elephant { private string name; private int earSize; public Elephant(string name, int earSize) { this.name = name; this.earSize = earSize; } public int EarSize { get { return earSize; } } public async void WhoAmIAsync() { MessageDialog md = new MessageDialog( "私の耳の大きさは" + earSize + "cmです。", name + "が言った・・・"); await md.ShowAsync(); } } }
0 コメント:
コメントを投稿