About 730,000 results
Open links in new tab
  1. Nullable type as a generic parameter possible? - Stack Overflow

    Oct 16, 2008 · The type 'int?' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method Is specifying a nullable type as a generic parameter at all possible?

  2. How can I pass in a func with a generic type parameter?

    Mar 24, 2014 · You can certainly define generic delegates, after all, that's exactly what Func and Action are. They are treated as generic definitions, just like generic interfaces and classes are. …

  3. c# - How to compare values of generic types? - Stack Overflow

    So, two questions: Why do we observe this weird behaviour? What keeps us from comparing the values of generic types which are known to be IComparable? Doesn't it somehow defeat the …

  4. How do I call a generic method using a Type variable?

    What's the best way to call a generic method when the type parameter isn't known at compile time, but instead is obtained dynamically at runtime? Consider the following sample code - …

  5. Generic Constraint for Non Nullable types - Stack Overflow

    Applying where T : struct applies a generic constraint that T be a non-nullable value type. Since there are no non-nullable reference types, this has the exact same semantics as simply "all …

  6. How can I create a generic array in Java? - Stack Overflow

    8 Java generics work by checking types at compile time and inserting appropriate casts, but erasing the types in the compiled files. This makes generic libraries usable by code which …

  7. How do I get the type name of a generic type argument?

    26 This extension method outputs the simple type name for non-generic types, and appends the list of generic arguments for generic types. This works fine for scenarios where you don't need …

  8. How do you provide a default type for generics? - Stack Overflow

    Jul 8, 2009 · The generic parameter type will be the same for all methods, so I would like it at the class level. I know I could make a generic version and then inherit from it for the int version, …

  9. How to define generic type limit to primitive types?

    Apr 30, 2009 · I have the following method with generic type: T GetValue<T>(); I would like to limit T to primitive types such as int, string, float but not class type. I know I can define generic for …

  10. Using Mockito to mock classes with generic parameters

    Is there a clean method of mocking a class with generic parameters? Say I have to mock a class Foo&lt;T&gt; which I need to pass into a method that expects a Foo&lt;Bar&gt;. I can do the …