c# - What is usage of this recuring generic class? -


This code has been compiled in Visual Studio, what is the use of it

  public Class Mayclass & lt; T & gt; Where T: Myclass & lt; T & gt;   

Note: Where T: MyClass & lt; T & gt;

This is usually used so that the base class can not change its actual type Could refer to This is done in an attempt to protect type-security, so track the current type in the parameter specified in the base class or in the return value order. For example,

  public class animals   

Be able to define the type of return to be animal basis class method only GiveBirth without type parameter < Code> Animal , which can reduce the type of security for customers.

If you control the entire hierarchy and can ensure that the classes provide the correct type of parameters, but note that it is a sad sad

  public square cat : Animals & lt; Dog & gt; {...}   

Another downside is that any client needs to take account of normal type of parameters, if they want to apply to the base class like

  public static zero feeds & lt; T & gt; (Animals  Animals) where T: Animals & lt; T & gt; {...} Public Stable Zero Feed & lt; T & gt; (T beast) Where T: Animals & lt; T & gt; {...}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -