コード例 #1
0
ファイル: Program.cs プロジェクト: josh-yates/LearningCsharp
        }                                                   //Auto property

        //Default constructor
        public Galaxy()
        {
            GalaxyHubbleType = HubbleType.E0;
            Redshift         = 0;
            TotalMass        = 1e7;
            MassFraction     = 0;
            Satellites       = new System.Collections.Generic.List <Galaxy> {
            };
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: josh-yates/LearningCsharp
 //Parameterised constructor
 public Galaxy(HubbleType HubbleTypeIn, double RedShiftIn, double TotalMassIn, double MassFractionIn)
 {
     if (RedShiftIn < 0 || RedShiftIn > 10)
     {
         throw new System.Exception("Redshift not in range");
     }
     if (TotalMassIn < 1e7 || TotalMassIn > 1e12)
     {
         throw new System.Exception("Total mass not in range");
     }
     if (MassFractionIn < 0 || MassFractionIn > 0.05)
     {
         throw new System.Exception("Mass fraction not in range");
     }
     GalaxyHubbleType = HubbleTypeIn;
     Redshift         = RedShiftIn;
     TotalMass        = TotalMassIn * SolarMass;
     MassFraction     = MassFractionIn;
     Satellites       = new System.Collections.Generic.List <Galaxy> {
     };
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: josh-yates/LearningCsharp
 public void AddSatellite(HubbleType HubbleTypeIn, double RedShiftIn, double TotalMassIn, double MassFractionIn)
 {
     Satellites.Add(new Galaxy(HubbleTypeIn, RedShiftIn, TotalMassIn, MassFractionIn));
 }