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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:59:39+00:00 2026-06-13T11:59:39+00:00

I have a class of this type: class A<TResult> { public TResult foo(); }

  • 0

I have a class of this type:

class A<TResult>
{
     public TResult foo();
}

But sometimes I need to use this class as a non generic class, ie the type TResult is void.
I can’t instantiate the class in the following way:

var a = new A<void>();

Also, I’d rather not specify the type omitting the angle brackets:

var a = new A();

I don’t want re-write the whole class because it does the same thing.

  • 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-13T11:59:39+00:00Added an answer on June 13, 2026 at 11:59 am

    The void isn’t a real type in C#, even there is a corresponding System.Void struct in FCL. I’m afraid you need a non-generic version here like this:

    class A
    {
       //non generic implementation
    }
    
    class A<T> : A
    {
       //generic implementation 
    }
    

    you can see in FCL there are System.Action/System.Action<T>, instead of System.Action<void>, as well as Task instead of Task<void>.

    EDIT From CLI specification(ECMA-335):

    The following kinds of type cannot be used as arguments in
    instantiations (of generic types or methods):

    Byref types (e.g., System.Generic.Collection.List`1<string&> is
    invalid)

    Value types that contain fields that can point into the CIL evaluation stack (e.g.,List<System.RuntimeArgumentHandle>)

    void (e.g.,List<System.Void> is invalid)

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

Sidebar

Related Questions

I have a generic class that takes a type T . Within this class
Lets say have this immutable record type: public class Record { public Record(int x,
I have a class like this: abstract class CrudResource extends Controller { type ResourceIdType
For example, i have this: class BasePacket { int header; int type; } class
I have class that looks like this: class A { public: class variables_map vm
I have a class this is annotated with @Path like so: @Path(widgets) @Produces(MediaType.APPLICATION_XML) public
I have the following class and extension class (for this example): public class Person<T>
Let's say we have this class: public class Moo { string _value; public Moo(string
I have a class with this structure: public class BusinessObject { public int Column1
I have this custom type: public struct PasswordString { private string value; public PasswordString(string

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.