|
- 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 entire purpose of generic constraints? How do I resolve this, or at least work around it?
- How can I pass in a func with a generic type parameter?
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 However, you cannot use generic definitions in method signatures, only parameterized generic types Quite simply you cannot do what you are trying to achieve with a delegate alone
- void in C# generics? - Stack Overflow
I have a generic method that takes a request and provides a response public Tres DoSomething<Tres, Treq>(Tres response, Treq request) { *stuff* } But I don't always want a response for my request, and I don't always want to feed request data to get a response I also don't want to have to copy and paste methods in their entirety to make minor changes What I want, is to be able to do this
- Can I make a generic optional, defaulting to a certain class?
My question is related to Is there a reasonable approach to quot;default quot; type parameters in C# Generics?, but using an inner generic class that approach doesn't work Given code like this:
- C# generic type constraint for everything nullable
The first suggestion using default is perfect! Now my template with a generic type being returned can return a null for objects and the default value for built-in types
- 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 following
- exception - Generic catch for python - Stack Overflow
Generic catch for python Asked 16 years, 6 months ago Modified 5 years, 2 months ago Viewed 134k times
- Using List lt;T gt; in C# (Generics) - Stack Overflow
That's not how generics work MyMethod(List<T> list) is an invalid method signature (unless your class is a generic class with a Type Parameter T)
|
|
|