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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:22:54+00:00 2026-05-11T21:22:54+00:00

Running .NET 2.0, I have a generic method with the following signature: static listType

  • 0

Running .NET 2.0, I have a generic method with the following signature:

static listType FillCollection<listType, objType>(IDataReader dr) where listType : ICollection<objType>, new()

it’s purposes is to translate a datareader into a collection of objects both of my choosing. My problem, which isn’t exactly a problem, is that when I call it, the call ends up looking something like this:

List<MyObject> data = FillCollection<List<MyObject>, MyObject>(dr);

I’m curious if there’s a way to cut out the redundancy of having to specify MyObject twice in the call. Ideally, I’d be able to only specify it once, along with the collection type and maintain the strong typed nature of the method. Adding another wrapper method to abstract the ICollection type sorta does the trick:

List<MyObject> data = FillList<MyObject>(dr);

static List<objType> FillList<objType>(dr)
{
    return FillCollection<List<objType>, objType>(dr);
}

But I’d rather not have a wrapper method for every collection i want to use.

Maybe I have no choice in the matter, but if so, I don’t have to like it! 😉

Thanks!

  • 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-11T21:22:54+00:00Added an answer on May 11, 2026 at 9:22 pm

    Personally, I’m not really sure why you need your method to be able to create multiple different implementations of ICollection. My inclination would be to have a method signature as follows, and just create a List inside the method and return it.

    static ICollection<T> FillCollection<T>(IDataReader dr) where T : class, new()
    

    If that’s not acceptable, then I’d go with Joseph’s answer.

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

Sidebar

Related Questions

I have a new ASP.NET MVC project (my first), and I had been running
So I have ASP.NET running on the server in IIS7. I think I'm going
We have a website running .NET 2.0 and have started using the ASP.Net HttpRuntime.Cache
I have CruiseControl.net running Visual Studio (2005/2008 - using devenv.com) as we need to
We have about 7 app servers running .NET windows services that ping a single
Our site is running ASP.NET 1.1, and I need to have ASP.NET 2.0 running
I have some .net apps running that I need to monitor for example, then
So i have a custom CMS running under .Net 3.5 written entirely in c#.
I have a .NET application running on windows. I want clicking on some page
I have a .Net application running on a 32 bit box. The application is

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.