intMethod と doubleMethod の 2 つのメソッドがありますが、intMethod が int 配列パラメーターを受け取り、doubleMethod が double 配列パラメーターを受け取ることを除いて、それらはまったく同じです。
オーバーロードを使用して同じメソッド名を使用できることはわかっていますが、それでもパラメーターだけが異なる 2 つのほぼ同一のメソッドになってしまいます。intMethod と doubleMethod を 1 つのメソッドに結合できる方法はありますか?
もしそうなら、いくつかのサンプルコードを提供できますか? 私はいくつかのサンプルコードではるかにうまく従うことができます. ありがとう
編集:人々は私の方法を投稿するように私に要求します、そしてあなたはそこに行きます:
データ配列が double[][] である同一のメソッド readDataDouble があります。
基本的に、このメソッドは CSV ファイルを読み取り、データを int 形式に変換します。最初の行は時間で、最初の列は日付です。
public static void readDataInt(string value, ref int[][] data, ref DateTime[] timeframe, ref DateTime[] date)
{
string inputFile = "D:\\temp.csv";
string[][] temp = null;
if (File.Exists(inputFile))
{
string[] proRataVolumeFile = File.ReadAllLines(inputFile);
temp = new string[proRataVolumeFile.Length][];
for (int i = 0; i < proRataVolumeFile.Length; i++)
{
temp[i] = proRataVolumeFile[i].Split(',');
}
}
//convert the string to int
date = new DateTime[temp.Length - 1];
timeframe = new DateTime[temp[0].Length - 1];
data = new int[temp.Length - 1][];
for (int i = 1; i < temp.Length; i++)
{
data[i - 1] = new int[temp[i].Length - 1];
for (int j = 1; j < temp[i].Length; j++)
{
if (temp[i][j].Length > 0)
data[i - 1][j - 1] = Convert.ToInt32(temp[i][j]);
}
}
for (int i = 1; i < temp.Length; i++)
{
date[i - 1] = Convert.ToDateTime(temp[i][0]);
}
for (int j = 1; j < temp[0].Length; j++)
{
timeframe[j - 1] = DateTime.Parse(temp[0][j]);
}
}