小编Mun*_*qar的帖子

使用单循环在Array中查找重复项

问题是有和未排序的数组,最大值应小于长度.我必须在数组中找到重复的记录.条件是只使用一次循环.这是我迄今取得的成就.我想知道是否有任何其他方法可以实现这一目标.

int[] Arr = { 9, 5, 6, 3, 8, 2, 5, 1, 7, 4 };
int[] Arr2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
for (int i = 0; i < Arr.Length; i++)
{
    if (Arr2[Arr[i]] == 0)
    {
        Arr2[Arr[i]] = Arr[i];
    }
    else
    {
        Console.WriteLine("duclicate found");
    }       
}
Run Code Online (Sandbox Code Playgroud)

c# arrays algorithm

5
推荐指数
1
解决办法
9325
查看次数

C#将2D数组转换为html表

我有一个2维字符串数组,我想将其转换为html表.当我运行下面的代码时,由于阵列的长度很长,它需要花费很多时间.

  string data = string.Empty;
        string table = string.Empty;

        #region new code
        data += "<div class=\"tab-content\">";


        table = " <table class=\"table data-table\">";
        table += "<tbody>";
        for (int row = 1; row < Data.GetLength(0); row++)
        {
            table += "<tr>";
            for (int column = 1; column < Data.GetLength(1); column++)
            {
                try
                {
                    table += "<td>" + Data[row, column].ToString() + "</td>";
                }
                catch
                {
                    table += "<td></td>";
                }
            }
            table += "</tr>";
        }
        table += "</tbody>";


        table += "</table>";
Run Code Online (Sandbox Code Playgroud)

.net html c# arrays

1
推荐指数
1
解决办法
1239
查看次数

标签 统计

arrays ×2

c# ×2

.net ×1

algorithm ×1

html ×1