IQueryable<T> , . , IQueryable<T>, # Type Inference , T . , Linq , , .
, , , :
public static IQueryable<T> FilterDefaults<T>(IQueryable<T> theSet)
{
IQueryable<T> query =
from t in theSet
where t != default(T)
select t;
return query;
}
, #, <T>, T , :
string[] myStrs = { "ABC", null, "", "123", null, "XYZ" };
var theFilteredStrs = FilterDefaults(myStrs);
// should represent the sequence: "ABC", "", "123", "XYZ"
// note null is missing because default(string) is null
int[] myNums = { -1, 0, 3, 0, 42 };
var theFilteredNums = FilterDefaults(myNums);
// should represent the sequence: -1, 3, 42
// note 0 is missing because default(int) is 0
, , LINQ ( LINQ-to-SQL), LINQ. , LINQ-to-SQL LINQ-to-Objects.