Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 列表c中的标记_C#_List_Tags - Fatal编程技术网

C# 列表c中的标记

C# 列表c中的标记,c#,list,tags,C#,List,Tags,我想在列表中检查对象的标记。对于与clean匹配的每个标记,需要提升一个整数。这可能吗?如果是,我如何才能做到这一点 提前谢谢 附言:这就是我现在拥有的 using UnityEngine; using System.Linq; using System.Collections; using System.Collections.Generic; public class productManager : MonoBehaviour { public string ownerNam

我想在列表中检查对象的标记。对于与clean匹配的每个标记,需要提升一个整数。这可能吗?如果是,我如何才能做到这一点

提前谢谢

附言:这就是我现在拥有的

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


public class productManager : MonoBehaviour {

    public string ownerName = "";
    public List<Transform> ingredients = new List<Transform>();
    //public int count = (from Object in List<Transform> ingredients where Object.Tags.Contains("clean") select Object).Count<Transform>();

    void Start(){
        ownerName = transform.name;
        name = ownerName + "'s ingredients";
    }

    void Update(){
        int count = (from Object in List<Transform> where Object.Tags.Contains("clean") select Object).Count<Transform>();
    }
}
您可以尝试使用Linq:

int count=从Object.Tags.Containsclean select Object.count所在列表中的对象开始

它将返回该列表中包含标记clean的对象数。

您可以尝试使用Linq:

int count=从Object.Tags.Containsclean select Object.count所在列表中的对象开始

它将返回该列表中包含标记clean的对象数。

如何:

var itemsWithCleanTag = myList.Where(item => item.Tag == "clean");

foreach(var item in itemsWithCleanTag)
{
    item.Raise(5);
}
那么:

var itemsWithCleanTag = myList.Where(item => item.Tag == "clean");

foreach(var item in itemsWithCleanTag)
{
    item.Raise(5);
}

完全可能,也很容易。建议在网上搜索,看看你能找到什么,然后问一个具体的问题。我已经试过了,但是在这个问题上找到一个简单的答案并不是那么容易。至少对我来说:完全可能,也很容易。建议在网上搜索,看看你能找到什么,然后问一个具体的问题。我已经试过了,但是在这个问题上找到一个简单的答案并不是那么容易。至少对我来说:S。谢谢你的回答,但我找不到办法让它起作用。你能帮我吗?我得到的结论是:找不到“Where”查询表达式模式的实现。错误检查我编辑的文章中最近的脚本。尝试以下操作:“int count=from o in components where o.Tags.contains清除选择o.count;”谢谢你的回答,但我找不到办法让它工作。你能帮我吗?我得到的结论是:找不到“Where”查询表达式模式的实现。错误检查我编辑的文章中最近的脚本。尝试以下操作:“int count=from o in components where o.Tags.contains清除选择o.count;”