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

  • Home
  • SEARCH
  • 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 6381881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:27:04+00:00 2026-05-25T02:27:04+00:00

Put default(T) in an interface. Explicitly implement the interface. The result does not compile

  • 0

Put default(T) in an interface. Explicitly implement the interface. The result does not compile

public interface IWhatever<T>
{
   List<T> Foo(T BarObject = default(T));
}

public class ConcreteWhatever: IWhatever<ConcreteWhatever>
{
    List<ConcreteWhatever> Foo(ConcreteWhatever BarObject = default(T)) {}
}

I fully expect default(ConcreteWhatever). What I get is default(T) which results in a compilation error.

I just go in and replace default(T) with null and things are fine. But this is hideous. Why is this happening?

  • 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-25T02:27:05+00:00Added an answer on May 25, 2026 at 2:27 am

    You don’t have a T in this case, because ConcreteWherever isn’t a generic type.

    If you want default(ConcreteWhatever) then that’s the code you should write.

    Are you just complaining about the code auto-generated by Visual Studio? If so, that’s a reasonable complaint, but it would be worth being explicit about it… (Note that you’re not using explicit interface implementation here – otherwise it would be declared as IWhatever<ConcreteWhatever>.Foo. You don’t really have properly implicit implementation either, as otherwise it should be public…)

    EDIT: I’ve just tried the same thing myself, and seen the same result, except the method is made public. Looks like it’s just a fault with Visual Studio – I suggest you create a Connect request for it. It’s a relatively rare situation though, I suspect – creating a generic interface which specifies an optional parameter which uses the default value of a type parameter as the value…

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

Sidebar

Related Questions

Whenever I send out emails in development mode, it does not put the localhost:3000
I put together a class yesterday to do some useful task. I started alpha
I'm extending a class (ArrayBlockingQueue) that implements the Serializable interface . Sun's documentation (and
I'm trying to implement a REST interface under IIS5.1/ASP-classic (XP-Pro development box). So far,
public interface ITaskProvider { T GetTask<T>(); } In the implementation of ITaskprovider below, as
Is it better to put a default implementation of a method in a superclass,
I have a static class 'Defaults' which shall hold default matrices that are forwarded
I have the following classes / interfaces: public interface IProjectRepository { IQueryably<Project> GetProjects(); }
Put differently: Is there a good reason to choose a loosely-typed collection over a
Put it another way: what code have you written that cannot fail. I'm interested

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.