C# 识别 for 循环中的项目

标签 c#

我创建了一个 for 循环,用于在每个部分显示 8 个项目,但我试图在循环中识别某些项目。例如,我想识别前两项,然后是第五项和第六项,但我的识别技术似乎是正确的。

for (int i = 0; i < Model.Count; i++){
    var item = Model[i]
    if ((i + 1) % 3 != 0 && (i + 1) % 4 != 0){
        // What i want to display here
    }
    else{
        // Something else I want to display
    }
}

这种方法对前四项有效,但对后四项似乎无效

最佳答案

for (int i = 0; i < Model.Count; i++){
    var item = Model[i]
    int aux = i%4;
    if (aux==0|| aux==1){
        // What i want to display here
    }
    else{
        // Something else I want to display
    }
}

关于C# 识别 for 循环中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41984472/

相关文章:

c# - DbConnection 超出范围时是否关闭并处置?

c# - 在 View 中禁用复选框

c# - 使用 MySqlCommand.ExecuteNonQuery 将几何数据插入表中

c# - 是否可以更改 Resharper 4.5 在 aspx/ascx 文件中格式化代码的方式?

c# - .NET 图表控件 - 将条形标签放在外侧和左侧吗?

c# - 更改 XAML 文件后 Visual Studio 挂起

C# 如何返回 null 或模型

c# - Xamarin 部署不适用于 Android

c# - CodeMaid vs Stylecop 使用组织

c# - 如何从包含 c#.net 中的 2 个元素的列表中单独获取第二个元素?