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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:30:48+00:00 2026-05-27T12:30:48+00:00

How do a turn this public static List<T> CreateListOfAnonymous<T>(T unused) {return new List<T>();} into

  • 0

How do a turn this

public static List<T> CreateListOfAnonymous<T>(T unused) {return new List<T>();}

into a lamda. I just can’t seem to work it out. as a generic of a generic gives an error

i.e:

Func<T,T> ..... fails because its looking for a real type.

My goal is to use the logic from that method above, but without a method, just internally inside some method.

  • 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-27T12:30:49+00:00Added an answer on May 27, 2026 at 12:30 pm

    My goal is to use the logic from that method above, but without a method, just internally inside some method.

    If the method or type you’re using the lambda in is generic (so that you have a type that is concrete in-context) then you can get this to work:

    public void SomeMethod<T>()
    {
        Func<T, List<T>> createList = CreateListOfAnonymous;
        var list = createList(default(T));
    }
    
    // ...
    
    class SomeClass<T>
    {
        public void SomeMethod()
        {
            Func<T, List<T>> createList = CreateListOfAnonymous;
            var list = createList(default(T));
        }
    }
    

    If neither is true for your code, or you want to keep T for the lambda as an open generic (potentially of some other type than the method or class’s generic parameters), then it won’t be possible, as leppie mentioned.

    I’ve found in cases where I’ve wanted to do this type of thing in the past (to avoid repeating myself), I only had a few types I wanted to bind to in the method. So I just bit the bullet and created one concrete version for each type I wanted to support:

    public void SomeMethod()
    {
        Func<List<string>> createStringList = () => CreateListOfAnonymous("");
        Func<List<int>> createIntList = () => CreateListOfAnonymous(0);
    
        var list1 = createStringList();
        var list2 = createStringList();
        var list3 = createStringList();
        var list4 = createIntList();
        var list5 = createIntList();
    
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It should turn this int Yada (int yada) { return yada; } into this
How can I turn this behavoir off? It happens when you enter a close
Trying to turn this: href=/wp-content/themes/tray/img/celebrity_photos/photo.jpg into: href=/img/celebrity_photos/photo.jpg So I'm simply trying to remove /wp-content/themes/tray/
Can't imagine this isn't a dupe but I can't seem find any previously matching
Given this extension method public static void Until(this Action action, Func<bool> booleanFunc) { while
public static void parseProfilesJson(String the_json){ try { JSONObject myjson = new JSONObject(the_json); JSONArray nameArray
For example this encryption function could be called a Utility ? public static string
how would you turn this array: array( 0 => Title1, 1 => Title2, 3
I would like to turn this query to regular inline sql without using stored
How do I turn this text: • Ban Ki-moon calls for immediate ceasefire• Residents

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.