<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx</link><description>In this post I’ll try to answer the most common questions I find on forums and in documentation feedback about C# covariance and contravariance. It’s a big topic for a single blog post, so expect to see a lot of “more information” links. 
 Special thanks</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10355550</link><pubDate>Wed, 03 Oct 2012 15:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10355550</guid><dc:creator>Ganesh</dc:creator><description>&lt;p&gt;Nice article, I understood the concept now after reading this article&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10355550" width="1" height="1"&gt;</description></item><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10291700</link><pubDate>Sun, 08 Apr 2012 01:21:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10291700</guid><dc:creator>Dima Kurguzov</dc:creator><description>&lt;p&gt;Sorry, string is not a value type, then it is not a boxing.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10291700" width="1" height="1"&gt;</description></item><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10291697</link><pubDate>Sun, 08 Apr 2012 00:27:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10291697</guid><dc:creator>Dima Kurguzov</dc:creator><description>&lt;p&gt;May be I am not right, but the first lines of code demonstrates the boxing not assigning of a more derived type to an object of a less derived type. Please correct me if I am wrong.&lt;/p&gt;
&lt;p&gt;string str = &amp;quot;test&amp;quot;;&lt;/p&gt;
&lt;p&gt;// An object of a more derived type is assigned to an object of a less derived type.&lt;/p&gt;
&lt;p&gt;object obj = str;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10291697" width="1" height="1"&gt;</description></item><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10259309</link><pubDate>Sun, 22 Jan 2012 01:34:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10259309</guid><dc:creator>Rajib Banerjee</dc:creator><description>&lt;p&gt;Object is less derived whereas any other type derived from object such as int or strings or such are more derived.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10259309" width="1" height="1"&gt;</description></item><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10133967</link><pubDate>Fri, 25 Feb 2011 09:15:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10133967</guid><dc:creator>Mr. Kashif Khan</dc:creator><description>&lt;p&gt;Rusina i could&amp;#39;t understand what does this mean &amp;quot;// An object of a more derived type is assigned to an object of a less derived type.&amp;quot;? what u mean more derived type and less derived type? &amp;nbsp;which is more derived type and which is less derived type? i am waiting eagerly for this answer so that i can learn this variance :( pls hlp&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10133967" width="1" height="1"&gt;</description></item><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10077124</link><pubDate>Mon, 18 Oct 2010 00:35:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10077124</guid><dc:creator>Mat Heuer</dc:creator><description>&lt;p&gt;@Alexandra Rusina: I would be glad if out-Parameters could be declared as covariant. &lt;/p&gt;
&lt;p&gt;Currently it seems as if out and ref Parameters are both treated invariant. &lt;/p&gt;
&lt;p&gt;Consider the bool TryGetValue(TKey key, out TValue value) Methods of IDictionary: &lt;/p&gt;
&lt;p&gt;Here the Type &amp;#39;value&amp;#39; should be declared as covariant. &lt;/p&gt;
&lt;p&gt;Currently I work around by switching both Return Values: &lt;/p&gt;
&lt;p&gt;TValue TryGetValue(TKey key, out bool isValid) &lt;/p&gt;
&lt;p&gt;But using this Signature is not as appealing AND the Parameter Type cannot be derived from a Return Value. &lt;/p&gt;
&lt;p&gt;Will this be supported in the foreseeable Future? &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10077124" width="1" height="1"&gt;</description></item><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10023551</link><pubDate>Fri, 11 Jun 2010 15:04:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10023551</guid><dc:creator>甜番薯</dc:creator><description>&lt;p&gt;I had translate this article to chinese.&lt;/p&gt;
&lt;p&gt;我已将此文章翻译成中文：&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.cnblogs.com/tianfan/archive/2010/05/17/covariance-and-contravariance-faq.html"&gt;www.cnblogs.com/.../covariance-and-contravariance-faq.html&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10023551" width="1" height="1"&gt;</description></item><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10006835</link><pubDate>Tue, 04 May 2010 04:40:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10006835</guid><dc:creator>Alexandra Rusina</dc:creator><description>&lt;p&gt;@admg&lt;/p&gt;
&lt;p&gt;The problems that C# had prior to version 4.0 due to the lack of variance support in generics are well-described here:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms228359%28VS.90%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms228359%28VS.90%29.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Note that this document is for C# 3.0, because now you should use variance in interfaces instead.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10006835" width="1" height="1"&gt;</description></item><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10006173</link><pubDate>Mon, 03 May 2010 07:32:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10006173</guid><dc:creator>z</dc:creator><description>&lt;p&gt;@admg&lt;/p&gt;
&lt;p&gt;In c#3.5 your statement would not compile. List&amp;lt;string&amp;gt; implements IEnumerable&amp;lt;string&amp;gt; which can not be cast to IEnumerable&amp;lt;object&amp;gt;. C#4.0 allows you to cast IEnumerable&amp;lt;string&amp;gt; to IEnumerable&amp;lt;object&amp;gt;.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10006173" width="1" height="1"&gt;</description></item><item><title>re: Covariance and Contravariance FAQ</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx#10005822</link><pubDate>Sat, 01 May 2010 23:15:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10005822</guid><dc:creator>admg</dc:creator><description>&lt;p&gt;Isnt it just hidden casting?&lt;/p&gt;
&lt;p&gt;IEnumerable&amp;lt;Object&amp;gt; objects = (IEnumerable&amp;lt;Object&amp;gt;) new List&amp;lt;String&amp;gt;();&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10005822" width="1" height="1"&gt;</description></item></channel></rss>