Constraint required default(T) is a valid T #4767
Unanswered
TonyValenti
asked this question in
Q&A
Replies: 2 comments 9 replies
-
Can you explain what you mean by "valid using System;
using System.Diagnostics.CodeAnalysis;
#nullable enable
public class C
{
public T? M<T>() => default(T);
} |
Beta Was this translation helpful? Give feedback.
3 replies
-
Maybe I need to clarify:
How do I constrain |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a method and I want to specific a constraint on T such that:
T can be a
struct
or T can be a
struct?
or T can be an
object?
Essentially I want to make sure that
default(T)
will always result in a valid ```T```` value.How can I do that?
Beta Was this translation helpful? Give feedback.
All reactions