開発環境
- OS: Windows 10 Pro
- IDE(統合開発環境): Visual Studio Community 2017
初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)、日向 俊二 (翻訳)、オライリージャパン)の6章(オブジェクト指向プログラミング)、6.8(練習問題)、問題6-2.を取り組んでみる。
コード
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Book book =
new Book(
"初めてのC#",
"Jesse Liberty, Brian MacDonald",
"487311294");
book.Shelve();
}
}
public class Book
{
private string title;
private string author;
private string isbn;
public Book(string title, string author, string isbn)
{
this.title = title;
this.author = author;
this.isbn = isbn;
}
public void Shelve()
{
Console.WriteLine(this);
Console.WriteLine("書棚に保管する。");
}
public override string ToString()
{
return String.Format(
"題名: {0}、著者: {1}、ISBN: {2}",
title, author, isbn);
}
}
}
入出力結果(コマンドプロンプト)
題名: 初めてのC#、著者: Jesse Liberty, Brian MacDonald、ISBN: 487311294 書棚に保管する。 続行するには何かキーを押してください . . .
0 コメント:
コメントを投稿