本文介绍了C#相当于range()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉在这里询问另一种语言,但是因为我只知道
Python而我正在尝试用C#写一些东西,我想这就是

最佳位置...


我想知道如何用C#写这个:


x = []

sz = 10000000

x.extend(范围(sz))


我的问题是关于范围和延伸。是否有相当于

C#?


提前致谢,

Neuruss

I''m sorry for asking about another language here, but since I only know
Python and I''m trying to write something in C#, I guess this is the
best place...

I''d like to know how to write this in C#:

x=[]
sz = 10000000
x.extend(range(sz))

My question is about "range" and "extend". Is there any equivalent in
C#?

Thanks in advance,
Neuruss

推荐答案




猜猜不好。在comp.lang.X上询问有关语言X的问题



Bad guess. Ask questions about language X on comp.lang.X





真的,这不是。在C#论坛中发帖,描述你想从你的程序中获得的

行为。


-

\"我在这个世界上唯一接受的暴君就是静止的声音。

` \ in。 - 圣雄甘地|

_o__)|

Ben Finney



Really, it isn''t. Post in a C# discussion forum, describing the
behaviour you want from your program.

--
\ "The only tyrant I accept in this world is the still voice |
`\ within." -- Mahatma Gandhi |
_o__) |
Ben Finney





List< int> mylist = new List< int>();

for(int i = 0; i< 10000000; i ++)

{

mylist。添加(i);

}


你可以使用AddRange,C#2.0匿名代表,IEnumerable,yield,

foreach,等等,但是对于你的例子来说这是最简单的。


另一种选择是使用嘘声。

It使用python的语法但速度与C#一样快。您在该代码中必须进行的唯一更改是将扩展方法调用大写。



List<int> mylist = new List<int>();
for (int i=0; i<10000000; i++)
{
mylist.Add(i);
}

You can use AddRange, C# 2.0 anonymous delegates, IEnumerable, yield,
foreach, and so forth instead, but for your example this is simplest.

Another option is to use boo. http://boo.codehaus.org/
It uses python''s syntax but is as fast as C#. The only change you''d
have to make in that code is to capitalize the Extend method call.


这篇关于C#相当于range()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 14:39