metodi ed array in out

  • Thread starter Thread starter kjqua
  • Start date Start date
K

kjqua

In una Classe vorrei inserire un metodo che accetti
un array in ingresso e che ne restituisca uno in uscita.

E da un po' che provo, ma senza riuscirci...
dove sbaglio?


ecco un esempio:

class Test
{
public static double[] nomeMetodo(double[] array_in)
{
double Lunghez = array_in.Length;
double[] arrayA = new double[Lunghez];

// Faccio qualche cosa

return arrayA;
}
}



grazie
 
Sorry herewith in English


In a Class i will like to write an method that it will accept one array
in input and then give back an other Array


it is possible ?
where i'm wrong?


example:

class Test
{
public static double[] nomeMetodo(double[] array_in)
{
double Lunghez = array_in.Length;
double[] arrayA = new double[Lunghez];

// Do something

return arrayA;
}
}



Thanks


kjqua ha scritto:
 
Sorry herewith in English


In a Class i will like to write an method that it will accept one array
in input and then give back an other Array


it is possible ?
where i'm wrong?


example:

class Test
{
public static double[] nomeMetodo(double[] array_in)
{
double Lunghez = array_in.Length;
double[] arrayA = new double[Lunghez];

// Do something

return arrayA;
}
}



Thanks

Hi,

Thank you for reposting in English. There is nothing wrong with your code other than it won't compile since you can't have an array that is above int in size. Array.Length is stored as an int but you can easily putan int inside a double, but you cannot to the opposite without casting.Change one of the lines to the below.

double Lunghez = array_in.Length; -> int Lunghez = array_in.Length;

or

double[] arrayA = new double[Lunghez]; -> double[] arrayA = new double[(int)Lunghez];

I suggest the first.
 
Thanks a lot, now is working.





Morten Wennevik [C# MVP] ha scritto:
Sorry herewith in English


In a Class i will like to write an method that it will accept one array
in input and then give back an other Array


it is possible ?
where i'm wrong?


example:

class Test
{
public static double[] nomeMetodo(double[] array_in)
{
double Lunghez = array_in.Length;
double[] arrayA = new double[Lunghez];

// Do something

return arrayA;
}
}



Thanks

Hi,

Thank you for reposting in English. There is nothing wrong with your code other than it won't compile since you can't have an array that is above int in size. Array.Length is stored as an int but you can easily put an int inside a double, but you cannot to the opposite without casting. Change one of the lines to the below.

double Lunghez = array_in.Length; -> int Lunghez = array_in.Length;

or

double[] arrayA = new double[Lunghez]; -> double[] arrayA = new double[(int)Lunghez];

I suggest the first.
 
Back
Top