-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
PrependToArray takes ref A[] args (non-nullable with nullable enabled) but still checks if (args == null). Either make the parameter nullable (ref A[]? args) if null is a supported input, or drop the null branch and rely on the compiler’s nullability. Also new A[0] can be replaced with Array.Empty<A>() and there are a few typos in the comments (e.g. "emptry").
Consider: make args nullable.
Also: Review possible migration to newer Params handler.
// Used when an overload takes a single param followed by a params [] array, and needs to prepend the single param to the param array
public static A[] PrependToArray<A>(A arg, ref A[] args) //where A : class
{
if (args == null) {
args = new A[0];// start with emptry array if was null
}
Array.Resize(ref args, args.Length + 1);// make room for new item
Array.Copy(args, 0, args, 1, args.Length - 1);// shift elements to the right to make room or new item
args[0] = arg;// prepend item to beginning
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels