コード例 #1
0
ファイル: Exercise.cs プロジェクト: chankevin234/C-Sharp-OOP
        public static void Start()
        {
            Console.WriteLine("Starting...");
            //objects below
            Guitar gibson = new Guitar(Brand.Gibson, 10);
            //Guitar fender = new Guitar("Fender", 100);

            Musician kevin  = new Musician("Kevin", new Guitar(Brand.Fender, 1000)); //"gibson" is the value of the Guitar class instanstance which is a data type accepted into Musicians class
            Musician pontus = new Musician("Pontus", new Guitar(Brand.Gibson, 100));

            kevin.Play();
            pontus.Play();

            Console.WriteLine(kevin.Guitar.Price); //objectName.className.propertyName
        }
コード例 #2
0
 //constructor
 public Musician(string name, Guitar guitar) //Guitar --> full Guitar object
 {
     Name   = name;
     Guitar = guitar;
 }