memoriaki
5/3/2018 - 10:39 PM

4-25-WindowsFormsApp2 #pro_OBJ

4-25-WindowsFormsApp2 #pro_OBJ

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 WindowsFormsApp2
{
    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();
        }

        private void button2_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;
            secondDoll.IntroduceYourself();
        }

        private void button3_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();
        }
    }
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 + "才です。");
        }
    }
}