コード例 #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     lloyd = lucinda;
     lloyd.TellMe("Hi", lucinda);
     lloyd.SpeakTo(lucinda, "Hello");
     lucinda.EarSize = 4321;
     lloyd.WhoAmI();
 }
コード例 #2
0
        private void btnSwap_Click(object sender, EventArgs e)
        {
            Elephant xTroca;// = new Elephant();
            xTroca = lucinda;
            lucinda = lloyd;
            lloyd = xTroca;
            //lloyd.WhoAmI();
            //lucinda.WhoAmI();
            MessageBox.Show("Objetos trocados");

        }
コード例 #3
0
        private void btnLoop_Click(object sender, EventArgs e)
        {
            Elephant[] elephants = new Elephant[7];

            elephants[0] = new Elephant { Name = "Lloyd", EarSize = 40 };
            elephants[1] = new Elephant { Name = "Lucinda", EarSize = 33 };
            elephants[2] = new Elephant { Name = "Larry", EarSize = 42 };
            elephants[3] = new Elephant { Name = "Lucile", EarSize = 32 };
            elephants[4] = new Elephant { Name = "Lars", EarSize = 44 };
            elephants[5] = new Elephant { Name = "Linda", EarSize = 37 };
            elephants[6] = new Elephant { Name = "Humprey", EarSize = 45 };

            Elephant biggestEars = elephants[0];

            for (int i = 1; i < elephants.Length; i++)
            {
                if (elephants[i].EarSize > biggestEars.EarSize)
                {
                    biggestEars = elephants[i];
                }
                MessageBox.Show(biggestEars.EarSize.ToString());
            }            
        }
コード例 #4
0
 public Form1()
 {
     InitializeComponent();
     lucinda = new Elephant() { Name = "Lucinda", EarSize = 33 };
     lloyd = new Elephant() { Name = "Lloyd", EarSize = 40 };
 }
コード例 #5
0
 public void SpeakTo(Elephant whoTalkTo,string message)
 {
     whoTalkTo.TellMe(message, this);
 }
コード例 #6
0
 public void TellMe(string message , Elephant whoSadIt)
 {
     MessageBox.Show(whoSadIt.Name + " says: " + message);
 }