反转列表< T> [英] reversing a list<T>

查看:50
本文介绍了反转列表< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码 

I have code like this 

public List<int> train = new List<int>();
train=train.Reverse();
train1[0]=wagonId;
train=train.Reverse();

但是2行所在地我正在将自己的火车转移给自己,我得到了 

but the 2 lines where I am assignmg train to itself reversed I get 

Compiler output: 
TrainComposition.cs(29,16): error CS0029: Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<int style="box-sizing:border-box;color:#525252;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:15px;">' 
TrainComposition.cs(31,15): error CS0029: Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<int style="box-sizing:border-box;">'</int></int>

任何想法有什么不对...我试图在左侧添加一个列表项是逆转点

any idea what is wrong ... I am trying to add a list item to the left side is the point of the reversing

推荐答案





public List<int> train = new List<int>();
train=train.Reverse();
train1[0]=wagonId;
train=train.Reverse();

但是2行所在地我正在将自己的火车转移给自己逆转了

but the 2 lines where I am assignmg train to itself reversed I get 

Compiler output: 
TrainComposition.cs(29,16): error CS0029: Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<int style="box-sizing:border-box;color:#525252;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:15px;">' 
TrainComposition.cs(31,15): error CS0029: Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<int style="box-sizing:border-box;">'</int></int>




反向训练只需使用



train.Reverse();



不要尝试分配回报,因为Reverse()方法有无效回报。



- Wayne

To reverse train just use

train.Reverse();

Don't try to assign the return, as the Reverse() method has a void return.

- Wayne


这篇关于反转列表&lt; T&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆