Menu



Manage

Study_C# > 11/Program.cs Lines 126 | 3.6 KB
다운로드

                        using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Weeks12
{
    internal class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Dof d = new Dof();
                Bird b = new Bird();
                Airplain a = new Airplain();

                List<Animal> animals = null;

                if (animals != null)
                {
                    for (int i = 0; i < animals.Count; i++)
                    {
                        animals[i].Eat();
                    }
                }

                animals = new List<Animal>();
                animals.Add(d);
                animals.Add(b);
                //animals.Add(a);
                foreach (var ani in animals)
                {
                    ani.Eat();
                    try
                    {
                        ((Bird)ani).Twitter();
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine("얘 새 아님, 못 지줘귐");
                    }

                    //int temp1; 주석처리
                    if(ani.NextAge(out int temp1))   //최신문법
                    {
                        Console.WriteLine("다음나이: " + temp1);
                    } else
                    {
                        Console.WriteLine("다음나이? 몰?루");
                    }

                    while (true)
                    {
                        try
                        {
                            ani.Age = int.Parse(Console.ReadLine());
                            break;
                        }
                        catch (FormatException fex)
                        {
                            Console.WriteLine("다시 입력해!");
                        }
                    }

                    if (ani.NextAge(out int temp2))   //최신문법
                    {
                        Console.WriteLine("다음나이: " + temp2);
                    }
                    else
                    {
                        Console.WriteLine("다음나이? 몰?루");
                    }

                }

                List<Ifliable> flyables = new List<Ifliable>();
                //flyables.Add(d);
                flyables.Add(b);
                flyables.Add(a);
                foreach (var fly in flyables)
                {
                    fly.Fly();
                    fly.Landing();
                }
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("Null 에러구만~");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally //마무리작업 있다면 사용
            {
                Console.WriteLine("사요나라 굿바잉");
            }
        }
    }
}
/* Java는 out이나 알리에프코드가 엇ㅂ는데?
 * 
 * class Xy
 * {
 *      public int x;
 *      public int y;
 * }
 * 
 * class Program
 * {
 *      static Xy NextPosition(int x, int y, int vx, invy){
 *          Xy xy = new Xy();
 *          xy.x = x + vx;
 *          xy.y = y + vy;
 *          return xy;
 *      }
 *      static void Main() {
 *          Xy a = NextPosition(0,0,1,1);
 *      }
 * }
 */

//링크랑 델리게이트는 안짚음
//디비는 현재 안씀 그리고 담주에 공부할 코드 주고 분석하면 됨