About 784,000 results
Open links in new tab
  1. How do I make the return type of a method generic?

    Apr 5, 2024 · This may not be a best practice but it worked for me. This method takes in an array of generic type and a value to add to the end of the array. The array is then copied with the …

  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. 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 …

  5. Create Generic method constraining T to an Enum

    Sep 17, 2008 · Create Generic method constraining T to an Enum Asked 16 years, 10 months ago Modified 1 month ago Viewed 528k times

  6. Can I make a generic optional, defaulting to a certain class?

    Dec 5, 2012 · My question is related to Is there a reasonable approach to "default" type parameters in C# Generics?, but using an inner generic class that approach doesn't work. …

  7. Creating a generic method in C# - Stack Overflow

    Jan 27, 2010 · I am trying to combine a bunch of similar methods into a generic method. I have several methods that return the value of a querystring, or null if that querystring does not exist …

  8. Generic constraints, where T : struct and where T : class

    Jun 4, 2010 · Actually, it is possible to differentiate the type of a method call based upon constraints if one doesn't mind having a dummy "optional" parameter of a generic reference …

  9. Cast to generic type in C# - Stack Overflow

    Jun 28, 2016 · 1 As mentioned, you cannot cast it directly. One possible solution is to have those generic types inherit from a non-generic interface, in which case you can still invoke methods …

  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<T> which I need to pass into a method that expects a Foo<Bar>. I can do the …