Why wouldn't this work?
I create the struct and want to return it by ref.
public readonly struct AuditResult
{
public readonly bool AcceptChanges;
public readonly string Reason;
public AuditResult(bool acceptChanges, string reason)
{
AcceptChanges = acceptChanges;
Reason = reason;
}
public static ref AuditResult AcceptAuditResult()
{
var auditResult = (new AuditResult(true, string.Empty));
ref AuditResult res = ref auditResult;
return ref res;
}
}
With this error happens:
CS8157 Cannot return 'res' by reference because it was initialized to a value that cannot be returned by reference
My variable is a ref in this case?