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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:14:25+00:00 2026-05-15T13:14:25+00:00

I have a method that is structured like this: public object Get(int intId, int

  • 0

I have a method that is structured like this:

    public object Get(int intId, int intWeekNumber)
    {
        try
        {
            if(intWeekNumber > -1)
            {
                switch(intId)
                {
                    case 1:
                        return ReportDB.GetReport1(intWeekNumber);//return object of type Report1
                    case 2:
                        return ReportDB.GetReport2(intWeekNumber);//return object of type Report2
                    case 3:
                        return ReportDB.GetReport3(intWeekNumber);//return object of type Report3
                    case 4:
                        return ReportDB.GetReport4(intWeekNumber);//return object of type Report4
                }
            }
        }
        catch(Exception ex)
        {
            LogError(ex);
        }

        return null;
    }

Rather than use object as the return type I like to make this a generic method, however I’m not sure how I would do it – can anyone suggest a good approach?

This method is called by the following code:

    public ActionResult Get(int intId, NameValue nvWeekNumber)
    {
        Type U = Utilities.GetReportType(intId);
        return new ObjectResult<object>(ReportManager.Instance.Get(intId, nvWeekNumber));
    }

The helper function GetReportType returns the type of report (e.g. Report1, Report2, Report3, etc) based on the parameter intId. When I try to use variable U instead of object I get an errors:

  • Argument ‘1’: cannot convert from ‘object’ to ‘U’
  • The type or namespace
    name ‘U’ could not be found (are you
    missing a using directive or an
    assembly reference?)

Any help would be greatly appreciated,

Mark

  • 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-05-15T13:14:26+00:00Added an answer on May 15, 2026 at 1:14 pm

    U is an actual variable, and variables cannot be used as generic parameters, only types can.

    I am not sure how you are using your report types, but I would suggest either making a base type (class or interface) Report that they all derive from. You could then use the more specific Report type as the generic parameter to your ObjectResult.

    interface Report
    {
        /* parameters that all reports should have */
    }
    
    class Report1 : Report
    {
        /* implementation details... */
    }
    
    class Report2 : Report
    {
        // ...
    }
    
    // more report types
    
    public ActionResult Get(int intId, NameValue nvWeekNumber)
    {
        return new ObjectResult<Report>(ReportManager.Instance.Get(intId, nvWeekNumber));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say we have a class that looks like this: class A { public:
I have method that returns Drawable , and if its Bitmap object is recycled
I have a method that prints private variable of the class. public class Test
I'd like to have an object that implements both the Map and the List
This benchmark appears to show that calling a virtual method directly on object reference
Let's say I have a structure named vertex with a method that adds two
I have method that returned NSManagedObject and I don't know what kind of NSManagedObject
I have method that returns module path of given class name def findModulePath(path, className):
I have a method that receives something and it needs to determine the type
I have a method that uses ARC and takes an NSError pointer and I

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.