C# 14 Extension Members & Generics #9675
Answered
by
HaloFour
TonyValenti
asked this question in
Q&A
-
How do you implement generic extension members in C# 14?
|
Beta Was this translation helpful? Give feedback.
Answered by
HaloFour
Sep 10, 2025
Replies: 1 comment 2 replies
-
Generic extension methods on generic extensions have the combination of the generic type parameters between the two declarations, so: public static class ExtensionMembers {
extension<T>(Base<T> This) {
public void GenericTest<TOther>() {
Console.WriteLine("TOther");
}
}
}
// must be called like this:
Base<int> b = ...;
b.GenericTest<int, string>(); This was already the case with extension methods, but more obvious given the way they are declared: public static class ExtensionMembers {
public static void GenericTest<T, TOther>(this Base<T> This) {
Console.WriteLine("TOther");
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
jnm2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generic extension methods on generic extensions have the combination of the generic type parameters between the two declarations, so:
This was already the case with extension methods, but more obvious given the way they are declared: