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 684899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:52:03+00:00 2026-05-14T01:52:03+00:00

Please see following methods. public static ProductsCollection GetDummyData(int? customerId, int? supplierId) { try {

  • 0

Please see following methods.

    public static ProductsCollection GetDummyData(int? customerId, int? supplierId)
    {
        try
        {
            if (customerId != null && customerId > 0)
            {
                Filter.Add(Customres.CustomerId == customerId);
            }

            if (supplierId != null && supplierId > 0)
            {
                Filter.Add(Suppliers.SupplierId == supplierId);
            }

            ProductsCollection products = new ProductsCollection();

            products.FetchData(Filter);

            return products;
        }
        catch
        {
            throw;
        }
    }

    public static ProductsCollection GetDummyData(int? customerId)
    {
        return ProductsCollection GetDummyData(customerId, (int?)null);
    }

    public static ProductsCollection GetDummyData()
    {
        return ProductsCollection GetDummyData((int?)null);
    }

1- Please advice how can I make overloads for both CustomerId and SupplierId because only one overload can be created with GetDummyData(int? ). Should I add another argument to mention that first argument is CustomerId or SupplierId for example GetDummyData(int?, string). OR should I use enum as 2nd argument and mention that first argument is CustoemId or SupplierId.

2- Is this condition is correct or just checking > 0 is sufficient -> if (customerId != null && customerId > 0)

3- Using Try/catch like this is correct?

4- Passing (int?)null is correct or any other better approach.

Edit:

I have found some other posts like this and because I have no knowledge of Generics that is why I am facing this problem. Am I right? Following is the post.

Overloaded method calling overloaded method

  • 1 1 Answer
  • 3 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-05-14T01:52:03+00:00Added an answer on May 14, 2026 at 1:52 am
    1. Why not just create separate GetCustomerData(int) and GetSupplierData(int) methods?
      (Along with GetData() and GetData(int,int) if you need them.)

    2. If you change your method arguments to int rather than int? then you only need to check (at your discretion) that they’re greater than 0.

    3. There’s no need for the try...catch in this situation. If all you’re doing is re-throwing the exception then don’t bother catching it in the first place.

    4. See 1 and 2 above.

    EDIT: Maybe something like this…

    public static ProductsCollection GetData()
    {
        return GetDataImpl(-1, -1);
    }
    
    public static ProductsCollection GetData(int customerId, int supplierId)
    {
        if (customerId <= 0)
            throw new ArgumentOutOfRangeException("customerId");
    
        if (supplierId <= 0)
            throw new ArgumentOutOfRangeException("supplierId");
    
        return GetDataImpl(customerId, supplierId);
    }
    
    public static ProductsCollection GetCustomerData(int customerId)
    {
        if (customerId <= 0)
            throw new ArgumentOutOfRangeException("customerId");
    
        return GetDataImpl(customerId, -1);
    }
    
    public static ProductsCollection GetSupplierData(int supplierId)
    {
        if (supplierId <= 0)
            throw new ArgumentOutOfRangeException("supplierId");
    
        return GetDataImpl(-1, supplierId);
    }
    
    private static ProductsCollection GetDataImpl(int customerId, int supplierId)
    {
        if (customerId > 0)
            Filter.Add(Customers.CustomerId == customerId);
    
        if (supplierId > 0)
            Filter.Add(Suppliers.SupplierId == supplierId);
    
        ProductsCollection products = new ProductsCollection();
        products.FetchData(Filter);
    
        return products;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get class methods in an object. Please see the following example
Please see following examples first, and which one is better? Could you compare some
Please see the following manifest. The Activity_1's primary objective has mapInfo refers to a
Please see the following code: List list = Collections.synchronizedList(new ArrayList()); // ... synchronized (list)
How do we update a textbox on ticking checkboxes? Please see the following code,
Please see this fiddle I want the scrolling div stop following when left div
Can someone please help me figure out a way to achieve the following (see
Please see below code: thrust::device_vector<int>::iterator whereToBegin = copyListOfNgramCounteachdoc.begin(); end = thrust::unique_by_key(end.first, end.first + numUniqueNgrams,end.second);
Please see the following code.In following code I want to download some data from
Please see the following block of code import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import

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.