<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.dotnetzone.gr:443/cs/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>.NET Framework</title><link>https://www.dotnetzone.gr:443/cs/forums/14/ShowForum.aspx</link><description>Θέματα για threading, remoting, reflection, exception handling, security, regex κλπ.</description><dc:language>el</dc:language><generator>CommunityServer 2.1 SP3 (Build: 20423.1)</generator><item><title>Απ: Generics and Inheritance</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/20500.aspx</link><pubDate>Fri, 17 Nov 2006 03:18:24 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:20500</guid><dc:creator>γιωργος μπακογιαννης</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/20500.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=20500</wfw:commentRss><description>&lt;img src="/cs/emoticons/emotion-1.gif" alt="Smile" /&gt;</description></item><item><title>Απ: Generics and Inheritance</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/20487.aspx</link><pubDate>Fri, 17 Nov 2006 02:36:56 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:20487</guid><dc:creator>Dimitris Papadimitriou</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/20487.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=20487</wfw:commentRss><description>(#*&amp;%)(@#*&amp;%@##$!! θα μας φάει το casting!&lt;br /&gt;
&lt;br /&gt;
@ baburanos : είναι η μόνη λύση που δουλεύει, αλλά θέλω να αποφύγω να κάνω casting και να μετατρέπω την basetype σε customtype.&lt;br /&gt;
&lt;br /&gt;
Ρε γ...ω. Αφού υπάρχει το customtype είναι derived από το basetype... γιατί να μην δουλεύει!&lt;br /&gt;
&lt;br /&gt;
Join the petition!&lt;br /&gt;
&lt;br /&gt;
"covariant and contravariant generic types in .net now!!!"&lt;br /&gt;
&lt;br /&gt;
"covariant and contravariant generic types in .net now!!!"&lt;br /&gt;
&lt;br /&gt;
"covariant and contravariant generic types in .net now!!!"&lt;br /&gt;
&lt;br /&gt;
(...τραγουδιέται όμως το "δεν υποχωρούμε αν δεν δικαιωθούμε"!!!)</description></item><item><title>Απ: Generics and Inheritance</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/20486.aspx</link><pubDate>Fri, 17 Nov 2006 02:29:05 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:20486</guid><dc:creator>PALLADIN</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/20486.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=20486</wfw:commentRss><description>Καλησπέρα Δημήτρη,&lt;br /&gt;
&lt;br /&gt;
το θέμα το έχουμε ξανασυζητήσει σε παλαιότερο thread...&lt;br /&gt;
&lt;br /&gt;
έχει να κάνει με το ζήτημα ότι δεν υποστηρίζονται covariant and contravariant generic types</description></item><item><title>Απ: Generics and Inheritance</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/20485.aspx</link><pubDate>Fri, 17 Nov 2006 02:04:10 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:20485</guid><dc:creator>γιωργος μπακογιαννης</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/20485.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=20485</wfw:commentRss><description>&lt;P&gt;Αυτό σου κάνει ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;internal&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;abstract&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;class&lt;/span&gt; BaseClass&amp;lt;MyType&amp;gt; where MyType : BaseType&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;public&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;abstract&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;int&lt;/span&gt; GetValue(MyType value);&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;internal&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;class&lt;/span&gt; CustomClass : BaseClass&amp;lt;BaseType&amp;gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;public&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;override&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;int&lt;/span&gt; GetValue(BaseType value) {&lt;br /&gt;            &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;return&lt;/span&gt; value.GetValue();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;internal&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;abstract&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;class&lt;/span&gt; BaseType&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;public&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;abstract&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;int&lt;/span&gt; GetValue();&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;internal&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;class&lt;/span&gt; CustomType : BaseType&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;public&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;override&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;int&lt;/span&gt; GetValue() {&lt;br /&gt;            &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;return&lt;/span&gt; 1;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;internal&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;class&lt;/span&gt; TestClass&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;public&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;void&lt;/span&gt; Test() {&lt;br /&gt;            BaseClass&amp;lt;BaseType&amp;gt; baseClass &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;new&lt;/span&gt; CustomClass();&lt;br /&gt;        }&lt;br /&gt;    }&lt;/span&gt;&lt;/P&gt;</description></item><item><title>Απ: Generics and Inheritance</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/20483.aspx</link><pubDate>Fri, 17 Nov 2006 01:53:59 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:20483</guid><dc:creator>Grigoris</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/20483.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=20483</wfw:commentRss><description>Generics and Casting&lt;br /&gt;
&lt;br /&gt;
The C# compiler only lets you implicitly cast generic type parameters to Object, or to constraint-specified types, as shown in Code block 5. Such implicit casting is type safe because any incompatibility is discovered at compile-time. &lt;br /&gt;
&lt;br /&gt;
Code block 5. Implicit casting of generic type parameters&lt;br /&gt;
&lt;br /&gt;
interface ISomeInterface&lt;br /&gt;
&lt;br /&gt;
{...}&lt;br /&gt;
&lt;br /&gt;
class BaseClass&lt;br /&gt;
&lt;br /&gt;
{...}&lt;br /&gt;
&lt;br /&gt;
class MyClass where T : BaseClass,ISomeInterface&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
   void SomeMethod(T t)&lt;br /&gt;
&lt;br /&gt;
   {&lt;br /&gt;
&lt;br /&gt;
      ISomeInterface obj1 = t;&lt;br /&gt;
&lt;br /&gt;
      BaseClass      obj2 = t;&lt;br /&gt;
&lt;br /&gt;
      object         obj3 = t;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The compiler lets you explicitly cast generic type parameters to any other interface, but not to a class:&lt;br /&gt;
&lt;br /&gt;
interface ISomeInterface&lt;br /&gt;
&lt;br /&gt;
{...}&lt;br /&gt;
&lt;br /&gt;
class SomeClass&lt;br /&gt;
&lt;br /&gt;
{...}&lt;br /&gt;
&lt;br /&gt;
class MyClass &lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
   void SomeMethod(T t)&lt;br /&gt;
&lt;br /&gt;
   {&lt;br /&gt;
&lt;br /&gt;
      ISomeInterface obj1 = (ISomeInterface)t;//Compiles&lt;br /&gt;
&lt;br /&gt;
      SomeClass      obj2 = (SomeClass)t;     //Does not compile&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
However, you can force a cast from a generic type parameter to any other type using a temporary Object variable: &lt;br /&gt;
&lt;br /&gt;
class SomeClass&lt;br /&gt;
&lt;br /&gt;
{...}&lt;br /&gt;
&lt;br /&gt;
class MyClass &lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
   void SomeMethod(T t)&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
   {&lt;br /&gt;
&lt;br /&gt;
      object temp = t;&lt;br /&gt;
&lt;br /&gt;
      SomeClass obj = (SomeClass)temp;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Needless to say, such explicit casting is dangerous because it may throw an exception at run time if the type argument used instead of the generic type parameter does not derive from the type to which you explicitly cast. Instead of risking a casting exception, a better approach is to use the is and as operators, as shown in Code block 6. The is operator returns true if the generic type parameter is of the queried type, and as will perform a cast if the types are compatible, and will return null otherwise. You can use is and as on both generic type parameters and on generic classes with specific type arguments. &lt;br /&gt;
&lt;br /&gt;</description></item><item><title>Απ: Generics and Inheritance</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/20480.aspx</link><pubDate>Fri, 17 Nov 2006 01:23:55 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:20480</guid><dc:creator>Dimitris Papadimitriou</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/20480.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=20480</wfw:commentRss><description>Διόρθωση! Η πρώτη γραμμή είναι αυτή:&lt;br&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;/span&gt;&lt;/span&gt;abstract class BaseClass&amp;lt;MyType&amp;gt; where MyType : BaseType&lt;br&gt;</description></item><item><title>Generics and Inheritance</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/20479.aspx</link><pubDate>Fri, 17 Nov 2006 01:16:09 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:20479</guid><dc:creator>Dimitris Papadimitriou</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/20479.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=20479</wfw:commentRss><description>Μπορεί κανείς να μου βρει γιατί δεν δουλεύει το παρακάτω σενάριο; (συμπολεμιστές vbάδες, sorry για την C#... οι κακιές παρέες βλέπετε!!! Το σενάριο θα ήταν ακριβώς το ίδιο και σε vb)&lt;br&gt;Ορίστε το σενάριο:&lt;br&gt;&lt;br&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;abstract&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;class&lt;/span&gt; BaseClass&amp;lt;MyType&amp;gt;&lt;br /&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;abstract&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;class&lt;/span&gt; BaseType&lt;br /&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;class&lt;/span&gt; CustomClass: BaseClass&amp;lt;CustomType&amp;gt;&lt;br /&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;class&lt;/span&gt; CustomType: BaseType&lt;/span&gt;&lt;br&gt;&lt;br&gt;Το σενάριο είναι ok, αλλά το παρακάτω βγάζει invalid cast:&lt;br&gt;&lt;br&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;public&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;void&lt;/span&gt; Test()&lt;br /&gt;{&lt;br /&gt;      CustomClass testInstance &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;new&lt;/span&gt; CustomClass();&lt;br /&gt;      BaseClass&amp;lt;BaseType&amp;gt; testInstance2 &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; (BaseClass&amp;lt;BaseType&amp;gt;)testInstance;&lt;br /&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;Για να κάνετε δοκιμές κατεβάστε την επισύναψη...&lt;br&gt;</description></item></channel></rss>