C#简化字符串数组的初始化。有没有办法在C#中优化以下代码

string[] createdBy = new string[totalRowCount];
for (long i = 0; i < totalRowCount; i++)
{
    createdBy[i] = userName;
}




int?[] defaultInd = new int?[totalRowCount];
        for (long i = 0; i < totalRowCount; i++)
        {
            if (i == 0)
            {
                defaultInd[i] = 1;
            }
            else
            {
                defaultInd[i] = 0;
            }
        }

最佳答案

string[] myIntArray = Enumerable.Repeat(userName, totalRowCount).ToArray();

关于c# - C#简化字符串数组的初始化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40113242/

10-11 23:31