|
- How do I make the return type of a method generic?
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 first value stripped and the value taken into the method is added to the end of the array The last thing is that I return the generic array
- 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
- 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?
- 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:
- 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)
- 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 non-nullable types"
- 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
- Create Generic method constraining T to an Enum
Create Generic method constraining T to an Enum Asked 16 years, 10 months ago Modified 30 days ago Viewed 528k times
|
|
|