# how to define as many as numbers? (console)

Page 1 of 1

## 7 Replies - 1013 Views - Last Post: 04 November 2011 - 07:10 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=254183&amp;s=f70c855b939c80836834e7ab285636a0&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 matanl1234

Reputation: 0
• Posts: 22
• Joined: 01-November 11

# how to define as many as numbers? (console)

Posted 03 November 2011 - 02:18 PM

i wrote the next code:

``` static int DiffNumbers (int num)
{
int numCounter=0;
if (num==0)
{
numCounter = 1;
}
while (num>0)
{
num = num / 10;
numCounter++;
}
```

how do i define "numCounter" ammount of numbers as int?
Is This A Good Question/Topic? 0

## Replies To: how to define as many as numbers? (console)

### #2 Tryparse

Reputation: 80
• Posts: 193
• Joined: 20-April 10

## Re: how to define as many as numbers? (console)

Posted 03 November 2011 - 02:42 PM

Are you trying to dynamically create variables (ints) at runtime? If so, your best bet is going to be to use an array or list.
```int[] numberArray = new int[numCounter];
//or
List<int> numberList = new List<int>(numCounter);
```

### #3 Ryano121

• D.I.C Lover

Reputation: 1460
• Posts: 3,286
• Joined: 30-January 11

## Re: how to define as many as numbers? (console)

Posted 03 November 2011 - 02:43 PM

I don't really understand your question. The numCounter variable is already of type int. Perhaps try modifying your question slightly?

### #4 matanl1234

Reputation: 0
• Posts: 22
• Joined: 01-November 11

## Re: how to define as many as numbers? (console)

Posted 03 November 2011 - 02:47 PM

how do i use the array or list later?

### #5 Tryparse

Reputation: 80
• Posts: 193
• Joined: 20-April 10

## Re: how to define as many as numbers? (console)

Posted 03 November 2011 - 03:36 PM

You can iterate through the array/list using a for or foreach loop, or you can access them via their indices.

### #6 matanl1234

Reputation: 0
• Posts: 22
• Joined: 01-November 11

## Re: how to define as many as numbers? (console)

Posted 04 November 2011 - 03:54 AM

how can i compare them to each other?

one of the list to all other of the list,
or one of the arrat to all other?

### #7 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5101
• Posts: 9,283
• Joined: 08-June 10

## Re: how to define as many as numbers? (console)

Posted 04 November 2011 - 06:17 AM

Your questions are too vague, and you haven't provided any attempted code implementing anything that has been suggested.

We can't help you this way. You must be much more specific in what you are asking, because frankly, I have absolutely no clue what you want.

### #8 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6500
• Posts: 14,343
• Joined: 02-June 10

## Re: how to define as many as numbers? (console)

Posted 04 November 2011 - 07:10 AM

Quote

I have a little C# experience but I need to write ...

You need to start there. I can't say "I have little experience in speaking Russian, but I have been assigned to write a mystery novel in Russian. Can you help me?"

We can help you by saying "First learn basic programming and the language of C#. Then take on assignments." Could someone here write this program for you? Sure. Could someone here map out all the processes you need to follow and do the Software Design part of this in the slim hope you could code it from there? Sure. But we don't volunteer to do the job that you're either getting paid for, or getting a grade for. You may want to read this.

For now, just work on the lessons. Do a self-teaching book from cover to cover. Then consider writing a program.

Don't try to create a useful working program to fit a need of yours (or a for-pay contract) as your introduction to coding project. When you are learning to code you don't know enough to code a program, let alone know how to engineer the architecture of a program. It would be like saying "I don't know how to read sheet music, or play an instrument. I think I'll write a 3 act opera as my first learning experience."

I don't say this to be mean. We've seen lots of new coders take this approach and we know it doesn't work. Trying to design your own programs before you understand the basics of the code language you've chosen just leads to problems, frustrations, and 'swiss-cheese' education (lots of holes).

Resources, references and suggestions for new programmers. - Updated Oct 2011
Spoiler