書籍クラス
using System;
using System.Collections.Generic;
using System.Text;
namespace model01
{
class Book
{
private string title;
private string note;
private int user_id;
public Book(string title, string note, int user_id)
{
this.title = title;
this.note = note;
this.user_id = user_id;
}
public string Title
{
get { return this.title; }
}
public string Note
{
get { return this.note; }
}
public int UserId
{
get { return this.user_id; }
}
}
}
ユーザーアカウントクラス
using System;
using System.Collections.Generic;
using System.Text;
namespace model01
{
class User
{
private string name;
private string sex;
private bool active;
private DateTime birth;
private double weight;
private int point;
public User(string name, string sex, bool active, DateTime birth, double weight, int point)
{
this.name = name;
this.sex = sex;
this.active = active;
this.birth = birth;
this.weight = weight;
this.point = point;
}
public string Name
{
set { this.name=value; }
get { return this.name; }
}
public string Sex
{
set { this.sex = value; }
get { return this.sex; }
}
public bool Active
{
get { return this.active; }
}
public double Weight
{
get { return this.weight; }
}
public int Point
{
get { return this.point; }
}
}
}
コンソールサンプル
using System;
using System.Collections.Generic;
using System.Text;
namespace model01
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("こんにちは、世界!");
DateTime dt1;
dt1 = DateTime.ParseExact("2004/08/24 20:23:06", "yyyy/MM/dd HH:mm:ss", null);
User User1 = new User("Yamada", "女", true, dt1, 13332.35,63);
Console.WriteLine("ユーザーの情報:" + User1.Name + " " + User1.Sex + " " + User1.Active + " " + dt1 + " " + " " + User1.Weight + " " + User1.Point);
User1.Name = "Suzuki";
User1.Sex = "男";
Console.WriteLine("ユーザーの情報:" + User1.Name + " " + User1.Sex + " " + User1.Active + " " + dt1 + " " + " " + User1.Weight + " " + User1.Point);
Book Book1 = new Book("title1", "note1", 34);
Console.WriteLine("本の情報:" + Book1.Title + " " + Book1.Note + " " + Book1.UserId);
Console.WriteLine("何かキーを押すと終了します。");
Console.ReadKey();
}
}
}