Refactor Code

  • Gravatar
    Calling an OverLoaded Method from Inside the OverLoaded Method

    by azamsharp on 6/16/2008 3:00:30 PM
  • This might be a very simple thing but what is the best way to call an overloaded method from inside the overloaded method. Let's say I have two overloads for the CheckIn method and I want to call the overload of CheckIn if the user supplies the parameters. Here is my solution.
  • public void CheckIn(DateTime checkInTime)
    {
    if (IsCheckedIn()) throw new ArgumentException("Employee already checked in");

    TimeCard card = new TimeCard(DateTime.Now, DateTime.Now, false);
    card.Employee = this;
    _timeCards.Add(card);
    }

    public void CheckIn()
    {
    CheckIn(DateTime.Now);
    }

  • Refactor it!
Please log in to refactor the code! Login