0

relatively new to C#.

I've written a function that is supposed to fill an array.

    public static void fill_array(Array tierkreiszeichen, int startdate, int zeichen_laenge) 
    {
        for (int i = 0; i < zeichen_laenge; i++) 
        {
            tierkreiszeichen[i] = new int[zeichen_laenge];
            tierkreiszeichen[i] = startdate + i;
        }

I want the function to take the array name as an argument, so if I call it by

fill_array(march, 30);

I want it to fill the values of the array "march" (I created the arrays preemptively)

So it's a rather simple problem. What I can't get to work is passing the name of the array as an argument. The compiler error I'm getting is

"Cannot apply indexing with [] to an expression of System.Array.

Any help shall be welcome & thank you in Advance.

3
  • 1
    instead of passing Array tierkreiszeichen, use int[] tierkreiszeichen Commented Apr 19, 2014 at 11:10
  • Your intent is unclear. If I call fill_array(march, 30); what contents should the array march acquire? Please give an example. Commented Apr 19, 2014 at 11:18
  • John's answer was what I was looking for. Thank you! Commented Apr 19, 2014 at 11:27

2 Answers 2

2

Replace This:

public static void fill_array(Array tierkreiszeichen, int startdate,
                                                             int zeichen_laenge) 

With This:

public static void fill_array(int [] tierkreiszeichen, int startdate, 
                                                             int zeichen_laenge) 
Sign up to request clarification or add additional context in comments.

1 Comment

Not enough to make it compile :(
0

I think you have to use Jagged Array.

You can find example over here

http://www.dotnetperls.com/jagged-array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.