Reverse方法如何反转现有列表并将其转换为数组? [英] How the Reverse method reverse a existing list and convert into an array?

查看:158
本文介绍了Reverse方法如何反转现有列表并将其转换为数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个要反转的列表,并从该反转列表中获取数组,以及此反转方法的工作原理?

请帮帮我.

谢谢.

Hello All,

I have a list which I want to reverse and get an array from that reversed list and how this reverse method works?

please help me.

Thank you.

推荐答案

您在List< t>中有Revesre和ToArray方法,这是什么问题?

请参阅: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx [^ ]

要查看如何使用反射器实现该功能,请在Visual Studio中启用.net源调试,或为其源代码启用google.
You have Revesre and ToArray methods in List<t>, what''s the problem?

See: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx[^]

To see how it is implemented use reflector, enable .net source debugging in visual studio, or google for it''s source code.


List<string> dinosaurs = new List<string>();

dinosaurs.Add("Pachycephalosaurus");
dinosaurs.Add("Parasauralophus");
dinosaurs.Add("Mamenchisaurus");
dinosaurs.Add("Amargasaurus");
dinosaurs.Add("Coelophysis");
dinosaurs.Add("Oviraptor");

string[] input = dinosaurs.Reverse().ToArray();


List<string> list = new List<string>();
list.Add("C++");
list.Add("C#");
list.Add("Java");
list.Add("Objective-C");

list.Reverse();
string[] array = list.ToArray();
for (int i = 0; i < array.Length; i++)
{
    Console.WriteLine(array[i]);
}


这篇关于Reverse方法如何反转现有列表并将其转换为数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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