如何将对象列表设置为类?

时间:2014-09-23 14:01:53

标签: c# vector arraylist xamarin

我有一个类,我将它放在" List<(Object)>",我需要删除此列表的第一个注册表并且与该类相等,但方法删除如果无效,则会显示消息:

  

"无法隐式转换类型void' to WebPortaoAPI.BleRequest'"

以下是代码:

public class SomeClass
{
    List<Object> requestQueue = new List<Object> (20);

    BleRequest currentRequest = null;//Another class

    requestQueue.Add(currentRequest);

    currentRequest = requestQueue.RemoveAt(0);
}

2 个答案:

答案 0 :(得分:1)

你在寻找吗?

public class SomeClass{
    ...

    List<Object> requestQueue = new List<Object> (20);

    BleRequest currentRequest = null;//Another class

    requestQueue.Add (currentRequest);

    currentRequest = requestQueue[0] as BleRequest;
    requestQueue.RemoveAt(0);
    ...
}

答案 1 :(得分:0)

方法List<T>.RemoveAt不会返回值 如果您需要队列行为,请考虑使用Queue<T>类而不是List<T>