void Start()
{
var Match = from s in _supplier
join b in _buyers on new { s.District } equals new { b.District }
select new
{
MatchSupplier = s,
MatchBuyer = b.Name
};
List<string> TempList = new List<string>();
foreach (var VARIABLE in Match)
{
if (!TempList.Contains(VARIABLE.MatchSupplier.District))
{
TempList.Add(VARIABLE.MatchSupplier.District);
}
else
{
Debug.Log(VARIABLE.MatchSupplier.District);
// create a var with the name of the VARIABLE.MatchSupplier.District
// create a var to record the number of each District repeating time
}
}
// Debug.log(${var(each District name)} {var(repeating time)})
Debug.Log(TempList.Count);
}
是否可以在不創建全域變數的情況下在本地完成所有操作?我要記錄每個區名和每個區名彈出的次數。自定義類
[可序列化]公共類供應商{
public string Name;
public string District;
public int Age;
}
[Serializable]
public class Buyer
{
public string Name;
public string District;
public int Age;
}
uj5u.com熱心網友回復:
我認為您想計算某些專案,因此您可能寧愿使用 aDictionary<string, int>并執行類似的操作
Dictionary<string, int> TempList = new();
foreach (var VARIABLE in Match)
{
var district = VARIABLE.MatchSupplier.District;
TempList.TryGetValue(district, out var count);
TempList[district] = count 1;
}
foreach(var kvp in TempList)
{
Debug.Log($"{kvp.Key} - {kvp.Value}");
}
稍微簡化的小提琴
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/532862.html
