通过列表中的位置查找obj

问题描述 投票:0回答:1

我正在尝试编写一个函数,使用户应该能够将obj存储到特定位置。当找到它时检查它是否可用,然后插入obj。

public bool AddStorageManual(I3D s, int spot)
{
    // find warehouselocation by position in list
    foreach (WareHouseLocation wareHouseLocation in locations)
    {
        for (int i = 0; i < locations.Count; i++)
        {
            spot = i;
            if(locations[i] == null) 
            {
                bool available = wareHouseLocation.hasAvailableVolumeForObject(s);
                if (available) 
                {
                    wareHouseLocation.storage.Add(s);
                }
            }
        }               
    }
}

但是我的代码需要一些帮助。

c# list search
1个回答
0
投票
public bool AddStorageManual(I3DStorageObject s, int spot)
{
    // find warehouselocation by position in list

    WareHouseLocation wareHouseLocation = locations[spot];
    bool available = wareHouseLocation.hasAvailableVolumeForObject(s);
    if (available) 
    {
        wareHouseLocation.storage.Add(s);
        return true;
    }

    return false;
}       
© www.soinside.com 2019 - 2024. All rights reserved.