Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:32:09+00:00 2026-06-18T11:32:09+00:00

I have a repository class that I want to add two methods to: public

  • 0

I have a repository class that I want to add two methods to:

public IEnumerable<OpenCall> OpenCalls()
{
    return something;
}

public IEnumerable<OpenCall> OpenCalls(DateTime start, DateTime endd)
{
    return something_slightly_different;
}

Inside each method I am going to call another method (AverageResolutions()) that returns a list of average resolutions. Obviously this method will also need to take 0 parameters or 2 parameters. The way I’m doing things at the moment I’m either going to end with two almost identical copies of OpenCalls(), or two almost identical copies of AverageResolutions(), altered slightly to allow for the DateTime parameters.

I think I’m doing this wrong – how can I just end up with one version of a method that will either take 0 or 2 parameters and then decide what to call further down the line if they are either null or not null?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:32:10+00:00Added an answer on June 18, 2026 at 11:32 am

    You could change the method signature to use optional arguments:

    public IEnumerable<OpenCall> OpenCalls(DateTime? start=null, DateTime? end=null)
    {
        if (start.HasValue && end.HasValue)
        {
            return something_slightly_different;
        }
        return something;
    }
    

    Note that you will need to make the DateTime-parameters nullable, because otherwise you wouldn’t be able to set default values (which have to be compile-time constants).

    For more information about nullable types, and the syntactic sugar (writing DateTime? instead of Nullable<DateTime> see the MSDN article on Nullable Types

    For more information about optional parameters see the Optional Arguments section of the MSDN article about Named and Optional Arguments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a repository class that inherits from a generic implementation: public namespace RepositoryImplementation
I have a generic repository as like that public class Repository<T> : IRepository<T> where
Say I have two separate classes, A and B. I also have Repository class
I have a Repository Class with the following method... public T Single<T>(Predicate<T> expression) {
Example I have a repository class (DAL): public class MyRepository : IMyRepository { public
I have a repository like: public class Repository<TEntity> : IRepository<TEntity> where TEntity : class,
I have the following Repository: Public Class PageRepository Private Shared _pages As BLL.PageCollection Shared
I have the following generic repository: public class GenericRepository<TEntity> where TEntity : class {
If i have the following IQueryable<T> Repository: public class OrderRepository : GenericRepository<Order>, IOrderRepository {
I have to create a class that will load all the dll's from repository

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.