C# for statement and arrays...

Associate
Joined
30 Mar 2004
Posts
1,148
Location
West Wing
Hi, i've been trying out a bit of programming using C# language in my spare time. Im a complete newbie so need things broken down to me if im to understand them.

I think I more or less understand OOP in a conceptual way and its fascinating! Just a matter of learning the language so i can get my ideas into code to do what I want.

So ive made a console application that asks the user for an integer, n.

Then i want to take every number from 1 up to n and enter into an array called step1[].

What control statement should I use and how exactly do i do this?

Thanks,
 
Thanks, that works fine.

I didn't know arrays were zero-indexed so I was getting an error: "index was outside the bounds of the array". I included the "-1" and that cures it.

I prefer the first option, shows whats happening up front.
 
Code:
//step5 - remove every 7th number after 7
            for (i = 14; i <= listLength; i = i + 7)
            {
                numList.Remove(i);
                //Console.WriteLine(i);
            }

There are several steps that remove certain numbers from the list, that eventually will leave just the prime numbers. Is it possible to collapse chunks of code to make it more manageable? I can imaging things getting very messy if I had to do something which needed more content.

Btw, it was just taking a while to crunch the numbers.
 
Back
Top Bottom