Advertisement
K1SR

Untitled

Jun 18th, 2025
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. public class DateRange
  2. {
  3.     public DateTime From { get; private set; }
  4.     public DateTime To { get; private set; }
  5.  
  6.     public DateRange(DateTime from, DateTime to)
  7.     {
  8.         // Self-validating
  9.         if (from > to)
  10.         {
  11.             throw new ArgumentException("From date cannot be after To date.");
  12.         }
  13.         From = from;
  14.         To = to;
  15.     }
  16.  
  17.     // Behavior-rich
  18.     public bool Includes(DateTime date)
  19.     {
  20.         return date >= From && date <= To;
  21.     }
  22.  
  23.     public bool OverlapsWith(DateRange other)
  24.     {
  25.         return From <= other.To && To >= other.From;
  26.     }
  27.  
  28.     // ... (Equals i GetHashCode metode za jednakost po vrednostima)
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement