.

Generics

Couple of ways.

Without specifying the type must have a constructor:

<code><span class="pln">T obj </span><span class="pun">=</span><span class="kwd">default</span><span class="pun">(</span><span class="pln">T</span><span class="pun">);</span><span class="com">//which will produce null for reference types</span><span class="pln">
</span></code>

With a constructor:

<code><span class="pln">T obj </span><span class="pun">=</span><span class="kwd">new</span><span class="pln"> T</span><span class="pun">();</span><span class="pln">
</span></code>

But this requires the clause:

<code><span class="kwd">where</span><span class="pln"> T </span><span class="pun">:</span><span class="kwd">new</span><span class="pun">()</span><span class="pln">
</span></code>

What's your thoughts on this?

*

Protected by WP Anti Spam