Click here to Skip to main content
15,171,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I'm tring to write a method that can return any nullable primitive type, or a string. I.E.
public T Read<t>(string value)
{
   // read code
   //[...]

   if (someCondition)
     return null;

   return (T)obj;
}
</t>


The question is what condition I should impose on T to make it so that I can return null's and nullable primitives. I can't say "where T : nullable" as nullable is sealed and I can't say "where T : class" as nullable primitives aren't reference types.

Ideas?
Posted
Updated 7-Jun-10 4:48am
v2

1 solution

Solution found - use return default(T) instead of null.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900