Params (parameter array)

With the params keyword you define an optional array of parameters for your method with can be called with a comma seperated list of parameters.

Example:

    class Program
    {
        static void Main(string[] args)
        {
             //setup our DI
            var serviceProvider = new ServiceCollection()
                .AddLogging()
                .AddSingleton<IParamsTest, ParamsTest>()
                .BuildServiceProvider();

            // get the object from the service proviced
            var paramsTest = serviceProvider.GetService();

            // call the method 
            foreach (var name in paramsTest.LogNames("teus", "adriaan", "gert"))
            {
                Console.WriteLine(name);
            } 
        }
    }

public interface IParamsTest
    {
        IEnumerable LogNames(params string[] names);
    }

    public class ParamsTest: IParamsTest
    {
        private ILogger log;

        public ParamsTest(ILoggerFactory logger)
        {
            log = logger.CreateLogger("test");
        }

        public IEnumerable LogNames(params string[] names)
        {
            foreach (var name in names)
            {
                yield return name;
            }
        }
    }

This example is a .net core console application configured with dependency injection. Be aware that for using the dependency injection features you must install the nuget package: Microsoft.Extensions.DependencyInjection. The params keyword let me call the method LogNames with comma seperated values instead of an object of the type string array. In this case the method is looping the passed values and returning each value. 

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!