開発環境
- OS: macOS High Sierra - Apple
- IDE(統合開発環境): Visual Studio for Mac
- プログラミング言語: C#
初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)、日向 俊二 (翻訳)、オライリージャパン)の10章(配列)、10.9(練習問題)、問題10-1.を取り組んでみる。
コード
using System;
namespace Sample10
{
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;
}
set
{
weight = value;
}
}
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
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 (var dog in dogs)
{
Console.WriteLine("Name: {0}, Weight: {1}", dog.Name, dog.Weight);
}
}
}
}
入出力結果(Terminal)
Name: Milo, Weight: 26 Name: Frisky, Weight: 10 Name: Laika, Weight: 50 Press any key to continue...
0 コメント:
コメントを投稿