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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:23:04+00:00 2026-06-09T10:23:04+00:00

Recently ReSharper suggested in my Visual Studio 2010 solution that I could use optional

  • 0

Recently ReSharper suggested in my Visual Studio 2010 solution that I could use optional parameter in one of my methods. I was surprised, as project was targeted to .NET 3.5 and as far as I know optional parameters were introduced with C# 4.0.

But I made a change and it compiled.

On the other hand I tried if covariance and contravariance work with .NET Framework 3.5 generic IEnumerable, and it didn’t. Could you advise what piece of knowledge I’m missing?

  • 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-09T10:23:05+00:00Added an answer on June 9, 2026 at 10:23 am

    Variance for generic interfaces and delegates was introduced in the .NET Framework 2.0, but only useable to developers until the C# 4.0 compiler was able to take advantage of that.

    It wasn’t until the .NET Framework 4 that the framework’s library types were updated for this type of variance. .NET 3.5 generic variance works fine with the C# 4 compiler, but only with your own types. This compiles just fine on the .NET Framework 3.5 with the C# 4 compiler.

    public interface IFoo<out T>
    {
        T Bar();
    }
    
    public class Baz<T> : IFoo<T>
    {
        public T Bar()
        {
            return default(T);
        }
    }
    
    public class Program
    {
        static void Main()
        {
            IFoo<IConvertible> foo = new Baz<string>();
        }
    }
    

    Peter Richie left a comment that bears enough importance that it should be a part of the answer:

    Variance has always in .NET, for example arrays of reference types have always been covariant. As well, method group variance has been around since .NET 2.0. What you’re talking about is the added generic interface variance abilities added to C# 4–often referred to as “Covariance and Contravariance in Generics” in the documentation.

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

Sidebar

Related Questions

I have recently started using Visual Studio 2010 and ReSharper 5.1. It's working pretty
Recently, my Visual Studio 2008(with Resharper 4.5) has started to reformat asp tags into
I recently upgraded to using ReSharper 5 (currently in beta). I noticed that in
I'm using one of the nightly resharper builds and recently I just came across
Recently I've found how to add a link to an item in Visual Studio
Recently, I was writing a class in which I discovered that I could reduce
I have a stack of code snippets imported into Visual Studio. Just recently, they
I've recently noticed that when I create private methods that set a few fields
I've just started using ReSharper with Visual Studio (after the many recommendations on SO).
I recently installed Resharper 6.1 in VS-2010 . I'm using it with a rich

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.