How to fill an array with default values in C# ?

To fill an array with the default values in C# , you can use the Enumerable.Repeat method to do it.

How to fill an array with default values in C# ?

Below is a sample code illustrating the usage of the Enumerable.Repeat method to fill an array with default values.

using System;
using System.Collections.Generic;
using System.Linq;

namespace AbundantCodeConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string[] inputStr = Enumerable.Repeat("Abundantcode.com's MCA Lab programs", 10).ToArray();

            foreach (var item in inputStr)
                Console.WriteLine(item);
            Console.ReadLine();
        }
    }
}
image