using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Doll firstDoll = new Doll();
firstDoll.Name = "花子";
firstDoll.Age = 3;
firstDoll.IntroduceYourself();
Doll secondDoll = new Doll();
secondDoll.Name = "太郎";
secondDoll.Age = firstDoll.Age * 2;
secondDoll.IntroduceYourself();
Doll thirdDoll = new Doll();
thirdDoll.Name = "次郎";
thirdDoll.Age = secondDoll.Age - 2;
thirdDoll.IntroduceYourself();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
class Doll
{
public string Name;
public int Age;
public void IntroduceYourself()
{
MessageBox.Show("私の名前は"
+ Name + "です。私の年齢は"
+ Age + "才です。");
}
}
}