Performance: should method return a class or struct?

Recently moved from python to C#. Developing math app. Looked through many questions at SO about class vs struct, so I would like an advice from experienced people regarding performance.

DETAILS

I have a method, and during its execution 6 double variables are calculated and about 6 double[] arrays of same lenght. I want my method to return all them "packed" into one variable. Not planning to change them, I just need a storage and acces to them. During execution of the app, method will be called many times, such storages will be created many times also (up to 40).

REPRODUCING EXAMPLE

public (???) Method (params)
{ 
 double return_value1 = actions_with_params1;
 double return_value2 = actions_with_params2;
 double[] return_array1 = actions_with_paramsin_a_loop1;
 double[] return_array2 = actions_with_paramsin_a_loop2;
}

... and so on. I want to return a variable holding both double s and double[] s. What should I use better insetafd of (???) ? Class or struct, regarding performance?

Thank you!


以下是我如何做的一个示例:

class Program
{
    static void Main(string[] args)
    {
        List<Container> myValueStorage = new List<Container>();

        for (int i = 1; i < WhateverAmountOfOperations; i++)
        {
            myValueStorage.Add(YourMethod(yourParams));
        }
    }

    public static Container YourMethod(yourParams)
    {
        //Perform your calculations and store your results in the following variables
        double[] double_results; //An array of doubles
        double[][] double_array_results; //An array of double arrays

        //Create and return a class object containing the values
        return new Container(double_results, double_array_results);
    }


}
class Container
{
    double[] _doubles { get; }
    double[][] _double_arrays { get; }
    public Container (double[] doubles, double[][] double_arrays)
    {
        _doubles = doubles;
        _double_arrays = double_arrays;
    }
}
链接地址: http://www.djcxy.com/p/78902.html

上一篇: 在C#中,具有本地作用域的对象是否使用堆栈?

下一篇: 性能:方法应该返回一个类或结构?