Forum Discussion

Pattison159's avatar
Pattison159
Copper Contributor
Sep 24, 2024

Possible to change method called inside foreach?

I have a created a function as below

 

public static ICustomers[]? SanitiseCustomers(this string[]? custVals, float boxed = 0.5f)
    {
        List<ICustomers> customers = [];

        foreach (var c in custVals)
        {
            customers.Add(c.Sanitize(boxed));
        }

        return [.. customers];
    }

 

I want to replace the Sanitize function within the foreach loop to a different method.

 

I dont want to copy and paste the function and create a new one and changing Sanitize to FriendlyBox but trying to see if there is a way to switch the method name depending on the way this function is called?

No RepliesBe the first to reply

Resources