need help with array

Category: c# language

Question

MastrChief on Sun, 11 Nov 2012 14:27:16


Hey guys. I need some help with my array. The way I want it to be is if I want it to write 3 I would enter 1 and when I do 2 it will write 6 and when I enter 3 it will do 9 etc... without having to write int[] {3, 6 ,9} or whatever. Can anyone help me with this?

 Thanks in advance.




Replies

Fernando Soto - MCSD on Sun, 11 Nov 2012 14:58:55


  

I have no idea what you are trying to do, can you be more specific?

  

MastrChief on Sun, 11 Nov 2012 15:15:29


Basically I want an array that has a value (example value is "3") and if I enter "1" in the textbox "3" will appear in another textbox. If I enter "2" then "6" will be in the textbox. It's a bit difficult to explain. Just say I tell it to have a default value entering "1" will give the default value and when I enter "2" I want it to double that value or if I enter 3 I want it to triple the value. Sorry that is the best I can explain it.


Michael CS on Sun, 11 Nov 2012 15:21:02


  The following code is what u wanted? please let me know if I have any misunderstooding.

  void ArrayWithNNumElements(int n)
        {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = (i + 1) * 3;
            }
        }



Please click the Mark as Answer button if a post solves your problem!


Fernando Soto - MCSD on Sun, 11 Nov 2012 15:33:15


  

Well then how does the array work into to the problem? Having an array is just going to limit the range of values you can use.

If you just need to do this, "Just say I tell it to have a default value and when I enter 2 i want it to double that value or if I enter 3 I want it to triple the value.",  what you can do is have a text box called value and another called multiplier place your default value in the text box called value and when you enter a digit in the multiplier text box execute a statement that will multiply the two values. Or am I missing something here?

   

MastrChief on Sun, 11 Nov 2012 15:47:33


thanks for your answers. I decided to give up on my project because im just too busy to be working on anything. sorry for wasting your time.