開発環境
- OS: Windows 10 Pro
- IDE(統合開発環境): Visual Studio Community 2017
Head First C# ―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Greene (著)、佐藤 嘉一 (監修, 監修)、木下 哲也 (翻訳)、オライリージャパン)の3章(オブジェクト指向になる! - わかりやすいコードにする)、自分で考えてみよう(p. 99)を取り組んでみる。
コード
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" /> --> </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(); Clown oneClown = new Clown(); oneClown.Name = "力ちゃん"; oneClown.Height = 170; DisplayAlert("", (oneClown.TalkAboutYourself() == "名前は力ちゃんで身長は170cmです。").ToString(), "cancel"); Clown anotherClown = new Clown(); anotherClown.Name = "ゴン太"; anotherClown.Height = 175; DisplayAlert("", (anotherClown.TalkAboutYourself() == "名前はゴン太で身長は175cmです。").ToString(), "cancel"); Clown clown3 = new Clown(); clown3.Name = anotherClown.Name; clown3.Height = oneClown.Height - 3; DisplayAlert("", (clown3.TalkAboutYourself() == "名前はゴン太で身長は167cmです。").ToString(), "cancel"); anotherClown.Height *= 2; DisplayAlert("", (anotherClown.TalkAboutYourself() == "名前はゴン太で身長は350cmです。").ToString(), "cancel"); } } public class Clown { public string Name; public int Height; public string TalkAboutYourself() { return "名前は" + Name + "で身長は" + Height + "cmです。"; } } }
0 コメント:
コメントを投稿