Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace init_record
- {
- class Galassia
- {
- private readonly string _codiceNGC;
- private readonly double _distanza;
- public string CodiceNGC { get; init; }
- public double Distanza {
- get => Distanza;
- init
- {
- if (value < 0) throw new ArgumentOutOfRangeException();
- _distanza = value;
- }
- } //milioni di anni luce
- //public Galassia(string CodiceNGC, double Distanza)
- //{
- // this.CodiceNGC = CodiceNGC;
- // this.Distanza = Distanza;
- //}
- }
- internal class Program
- {
- static void Main(string[] args)
- {
- //Galassia andromeda = new Galassia("224", 2.537);
- //andromeda.CodiceNGC = "224";
- //andromeda.Distanza = 2.537;
- Galassia andromeda = new Galassia
- {
- CodiceNGC = "224",
- Distanza = -2.537
- };
- //andromeda.CodiceNGC = "sadlfjdo"; NO! Read Only ...
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement