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 WindowsFormsApp3
{
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;
Doll secondDoll = new Doll();
secondDoll.Name = "太郎";
secondDoll.Age = firstDoll.Age * 2;
Doll thirdDoll = new Doll();
thirdDoll.Name = "次郎";
thirdDoll.Age = secondDoll.Age - 2;
thirdDoll.IntroduceYourself();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
Doll fourthDoll = new Doll();
fourthDoll.Age = 5;
fourthDoll.IntroduceYourAge();
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
Doll fifthDoll = new Doll();
fifthDoll.Name = "三郎";
fifthDoll.IntroduceYourName();
}
}
}
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 + "才です。");
}
public void IntroduceYourName()
{
MessageBox.Show("私の名前は" + Name + "です。");
}
public void IntroduceYourAge()
{
MessageBox.Show("私の年齢は" + Age + "才です。");
}
}
}