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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:09:18+00:00 2026-05-20T14:09:18+00:00

From Wikipedia : covariant : converting from wider (double) to narrower (float). contravariant :

  • 0

From Wikipedia:

covariant: converting from wider (double) to narrower (float).
contravariant: converting from narrower (float) to wider (double).

In .NET, a delegate has covariance because it allows for derived types of the delegate’s specified return type to be the return type of a method that it holds a reference to.

As well a delegate has contravariance because it allows for derived types of the delegate’s specified arguments (parameters) to be the argument type passed into the method that it holds a reference to.

With these two definitions as they pertain to delegates, shouldn’t they both be covariance? In both cases, the delegate expects a “wider” type, but is given a “narrower type”.

See here for an example of both from MSDN.

So how does the word contravariance make sense, linguistically, when pertaining to delegates?

  • 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-20T14:09:18+00:00Added an answer on May 20, 2026 at 2:09 pm

    I now disagree with the answer from SeanVDH. He says “Linguistically, this seems to be logical in the sense of parameters versus return- so the direction forward or backward is with regards to going in or coming out of the function”.

    Instead I think this is the answer which comes from here:

    Covariance preserves assignment compatibility and contravariance reverses it. Covariance is a widening conversion, and contravariance is a narrowing conversion.

    When you instantiate a delegate, you
    can assign it a method that has a more
    derived return type than that
    specified in the delegate
    (covariance). You can also assign a
    method that has parameter types less
    derived than those in the delegate
    (contravariance). Emphasis added

    Example:

    static object GetObject() { return null; }
    static void SetObject(object obj) { }
    
    static string GetString() { return ""; }
    static void SetString(string str) { }
    
    static void Main()
    {
        // Covariance. A delegate specifies a return type as object,
        // but I can assign a method that returns a string.
        Func<object> del = GetString;
    
        // Contravariance. A delegate specifies a parameter type as string,
        // but I can assign a method that takes an object.
        Action<string> del2 = SetObject;
    
        // But implicit conversion between generic delegates is not supported until C# 4.0.
        Func<string> del3 = GetString;
        Func<object> del4 = del3; // Compiler error here until C# 4.0.
    }
    

    This realization was the result of reading Eric Lippert’s article, the Covariance and contravariance section of the Fast-tracked delegates chapter in Jon Skeet’s book C# In Depth, as well as the link above where the quote was drawn from.

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

Sidebar

Related Questions

From Wikipedia : Generic programming is a style of computer programming in which algorithms
From Wikipedia, the free encyclopedia: Closure (computer science) In computer science, a closure is
From wikipedia: the cross product is a binary operation on two vectors in a
The image above is from Wikipedia's entry on AVL trees which Wikipedia indicates is
I've read conflicting things on this. From Wikipedia: Controller Processes and responds to events,
From the wikipedia entry on NP-Complete: The easiest way to prove that some new
From http://en.wikipedia.org/wiki/AJAX , I get a fairly good grasp of what AJAX is. However,
More information from the Perl 6 Wikipedia entry Junctions Perl 6 introduces the concept
Ever wonder what wikipedia's database schema looks like? I recently read this thread from
From wikipedia's entry on DLR , it look like the purpose of DLR 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.