C# equivalent to range()

N

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
 
J

John Machin

Neuruss said:
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...

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

Ben Finney

Neuruss said:
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...

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

D H

Neuruss said:
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

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.
 
N

Neuruss

John said:
Bad guess. Ask questions about language X on comp.lang.X

Well, perhaps I should.
And I should also explain how range and extend work in python, which is
almost the same thing...

I thougt that maybe some python programmer could have experience here
with c# and give me a little hint.

But unfortunately, there are people here who are not willing to waste
their time helping, but enjoy to waste their time niggling...

Thanks anyway!
Neuruss
 
N

Neuruss

Thank you DH!!



D said:
Neuruss said:
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

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.
 
J

John Machin

Neuruss said:
Well, perhaps I should.
And I should also explain how range and extend work in python, which is
almost the same thing...

I thougt that maybe some python programmer could have experience here
with c# and give me a little hint.

But unfortunately, there are people here who are not willing to waste
their time helping, but enjoy to waste their time niggling...

Plonk.
 
E

Erik Max Francis

Neuruss said:
I thougt that maybe some python programmer could have experience here
with c# and give me a little hint.

But unfortunately, there are people here who are not willing to waste
their time helping, but enjoy to waste their time niggling...

Yeah, what jerks. They actually wanted to talk about Python, not some
random other language that you're trying to learn that has nothing to do
with it ...
 
?

=?iso-8859-1?q?Luis_M._Gonz=E1lez?=

Erik said:
Yeah, what jerks. They actually wanted to talk about Python, not some
random other language that you're trying to learn that has nothing to do
with it ...

There are thousands of threads to choose from in this forum.
If they didn't like this question, they could have picked any other one
to discuss.
There's no need to be disagreeable :)

Luis
 
M

Michel Claveau

Hi!
There are thousands of threads to choose from in this forum.
If they didn't like this question, they could have picked any other one
to discuss.
There's no need to be disagreeable :)

I think the same thing.
 
E

Erik Max Francis

Luis said:
There are thousands of threads to choose from in this forum.
If they didn't like this question, they could have picked any other one
to discuss.
There's no need to be disagreeable :)

Plenty of people _did_ helpfully respond to his question with the right
answer. The right answer is: This is the wrong forum; as your question
in a C#-related forum.

It was then the _original poster_ who became "disagreeable" by assigning
motive to the people who _actually helped him_ by telling him the right
place to ask his question, saying that the "enjoy to waste their time
niggling."

He's complaining that people weren't nice to help. But they _were_.
They answered his question politely and to the point. It's _he_ that
turned rude after that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,301
Messages
2,571,549
Members
48,295
Latest member
JayKillian
Top