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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:59:23+00:00 2026-06-10T00:59:23+00:00

Am I able to make this method generic? public static List<int> GetUnshippedOrders(string server,string port,string

  • 0

Am I able to make this method generic?

  public static List<int> GetUnshippedOrders(string server,string port,string database,string username,string password, string orderStatus)
  {
        var orderNumbers = new List<int>();
        using (var conn = ConnectToMySql(server, port, database, username, password))
        {            
           var command = new MySqlCommand("SELECT OrderNumber FROM orders WHERE OrderStatus = @orderStatus;", conn);
            command.Parameters.AddWithValue("@orderStatus", orderStatus);
            var reader = command.ExecuteReader();
            while (reader.Read())
            {
                orderNumbers.Add(Convert.ToInt32(reader[0])); 
            }
        } 
        return orderNumbers;
   }

I want to be able to handle various return types as the order number referenced to will change depending upon the schema of the database being connected to, I would prefer not to have to overload this method for each possible return type (plus I want to learn generics).

The database schema is dictated by various web services, none of which are under my control.
Also of special note, orderStatus can be a variety of types as well ( mostly string and int)

  • 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-10T00:59:24+00:00Added an answer on June 10, 2026 at 12:59 am

    If the logic to determine the return type is internal to the method, a generic return type isn’t going to help since you need to be able to specify the return type when calling a generic method. You could change the return type to List<object> and then handle casting back to the concrete type after the method returns. It’s ugly, but it works.

    If the caller knows what type to expect when calling the method, you could simply change List<int> to List<T> and support generics that way.

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

Sidebar

Related Questions

I have an extension method I'm trying to make generic, for message passing. public
I am not able to make this out: Between eliminates use of >= and
I'm not being able to make this line work with Tk import os while(1):
I am not able to make a clear decision on this one. I am
I just learned about this fine looking syntax Collections.<String>emptyList() to get an empty List
I have a generic method that takes a request and provides a response. public
I have been able to make my photos large for single photo posts on
I am not able to make the nested elements sortable in jQuery UI. I
I need to be able to make a program that looks through a mailbox
I need to be able to make a tree like structure in the appengine

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.