開発環境
- OS: Windows 10 Pro
- IDE(統合開発環境): Visual Studio Community 2017
Head First C# ―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Greene (著)、佐藤 嘉一 (監修, 監修)、木下 哲也 (翻訳)、オライリージャパン)の2章(あくまでコードである - 内部では)、自分で考えてみよう(p. 71)を取り組んでみる。
コード
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> <!-- Place new controls here --> <!-- <Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" /> --> <Button Text="button1" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" Clicked="Button_Clicked"/> </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(); } private void Button_Clicked(object sender, EventArgs e) { int t = 0; string result = ""; int count = 5; while (count > 0) { t++; count *= 3; count *= -1; } result += "ループ#1 " + (t == 1); result += "\nループ#2 無限ループ"; t = 0; int j = 2; for (int i = 1; i < 100; i *= 2) { t++; j = j - i; while (j < 25) { j += 5; } } result += "\nループ#3 " + (t == 7); t = 0; result += "\nループ#4 無限ループ"; t = 0; int p = 2; for (int q = 2; q < 32; q *= 2) { t++; while (p < q) { p *= 2; } q = p - q; } result += "\nループ#5 " + (t == 8); DisplayAlert("自分で考えてみよう", result, "cancel"); } } }
0 コメント:
コメントを投稿