開発環境
- OS: Windows 10 Pro
- IDE(統合開発環境): Visual Studio Community 2017
Head First C# ―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Greene (著)、佐藤 嘉一 (監修, 監修)、木下 哲也 (翻訳)、オライリージャパン)の2章(あくまでコードである - 内部では)、自分で考えてみよう(p. 71)を取り組んでみる。
コード
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; // MessageDialog // 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x411 を参照してください namespace App { /// <summary> /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。 /// </summary> public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); MyClass.DoSomethingAsync(); } } class MyClass { public static async void DoSomethingAsync() { int t = 0; int count = 5; while (count > 0) { t += 1; count *= 3; count *= -1; } string result = "ループ#1: " + (count == -15) + " 実行回数: 1回: " + t; t = 0; result += "\nループ#3: 無限ループ"; int j = 2; for (int i = 1; i < 100; i *= 2) { t += 1; j -= i; while (j < 25) { j += 5; } } result += "\nループ#3: " + (j == 25) + " 実行回数: 7回 " + t; t = 0; result += "\nループ#4: 無限ループ"; int p = 2; for (int q = 2; q < 32; q *= 2) { t += 1; while (p < q) { p *= 2; } q = p - q; } result += "\nループ#5: " + (p == 16) + " 実行回数: 8回 " + t; MessageDialog md = new MessageDialog(result); await md.ShowAsync(); } } }
0 コメント:
コメントを投稿