開発環境
- OS: Windows 10 Pro
- IDE(統合開発環境): Visual Studio Community 2017
初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)、日向 俊二 (翻訳)、オライリージャパン)の10章(配列)、10.9(練習問題)、練習10-1.を取り組んでみる。
コード
using System; class Dog { private int weight; private string name; public Dog(int weight, string name) { this.weight = weight; this.name = name; } public int Weight { get { return weight; } } public string Name { get { return name; } } } class Program { static void Main(string[] args) { Dog milo = new Dog(26, "Milo"); Dog frisky = new Dog(10, "Frisky"); Dog laika = new Dog(50, "Laika"); Dog[] dogs = { milo, frisky, laika }; foreach (Dog dog in dogs) { Console.WriteLine( "名前: {0}、重さ: {1}", dog.Name, dog.Weight); } } }
入出力結果(コマンドプロンプト)
名前: Milo、重さ: 26 名前: Frisky、重さ: 10 名前: Laika、重さ: 50 続行するには何かキーを押してください . . .
0 コメント:
コメントを投稿