小编sat*_*urn的帖子

列表数组初始化c#

List<authorinfo> aif = new List<authorinfo>();
for (int i = 0; i < 5; i++)
{
    aif.Add(null);
}
aif[0] = new authorinfo("The Count of Monte Cristo", "Alexandre", "Dumas", 1844);
aif[1] = new authorinfo("Rendezvous with Rama", "Arthur", "Clark", 1972);
aif[2] = new authorinfo("The Three Musketeers", "Alexandre", "Dumas", 1844);
aif[3] = new authorinfo("Robinson Crusoe", "Daniel", "Defoe", 1719);
aif[4] = new authorinfo("2001: A Space Odyssey", "Arthur", "Clark", 1968); 
//authorinfo ai = new authorinfo("The Count of Monte Cristo", "Alexandre", "Dumas", 1844); 
foreach (authorinfo i in …
Run Code Online (Sandbox Code Playgroud)

c# arrays list object

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

嵌套的foreach循环c#

        foreach (int i in a.set)
        {
            foreach (int k in b.set)
            {
                if (i < k)
                {
                    return true;                                
                }
                else if (i > k)
                {
                    return false;
                }
            }
        }


        return false;
    }
Run Code Online (Sandbox Code Playgroud)

我有两套,一套包括3,4,6 b.set包括3,4,5

问题是外循环只迭代一次.但它包含3个元素,为什么呢?

c# foreach loops

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×2

arrays ×1

foreach ×1

list ×1

loops ×1

object ×1