Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace OOP_4_Costruttori_1
- {
- class Data
- {// membri interni
- //field
- private int g;
- private int m;
- private int a;
- public Data(int _g, int _m, int _a) {
- G = _g; M = _m; A = _a;
- }
- public Data() { }
- public int G
- {
- get => g;
- set
- {
- if (value > GiorniMese() || value < 1)
- throw new InvalidOperationException();
- else g = value;
- }
- }
- public int M
- {
- get => m;
- set
- {
- if (value > 12 || value < 1)
- throw new InvalidOperationException();
- else m = value;
- }
- }
- public int A
- {
- get => a;
- set
- {
- if (value < 1)
- throw new InvalidOperationException();
- else a = value;
- }
- }
- //metodi
- int GiorniMese() //parametri formali
- {
- switch (m)
- {
- case 4:
- case 6:
- case 9:
- case 11:
- return 30;
- case 2:
- return 28 + (a % 400 == 0 || (a % 4 == 0 && a % 100 != 0) ? 1 : 0);
- default:
- return 31;
- }
- }
- public void SettaData(int gg, int mm, int aa )
- {
- G = gg; M = mm; A = aa;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Data d = new Data(15,10,10);
- //Data d2 = new Data("15-10-20");
- // Data d3 = new Data(15, "Ottobre", "20");
- //d.SettaData(15, 10, 10);
- Console.WriteLine(d.G);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement