daily pastebin goal
88%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void readDataInt(string value, ref int[][] data, ref DateTime[] timeframe, ref DateTime[] date)
  2.     {
  3.         string inputFile = "D:\temp.csv";
  4.         string[][] temp = null;
  5.  
  6.         if (File.Exists(inputFile))
  7.         {
  8.             string[] proRataVolumeFile = File.ReadAllLines(inputFile);
  9.             temp = new string[proRataVolumeFile.Length][];
  10.  
  11.             for (int i = 0; i < proRataVolumeFile.Length; i++)
  12.             {
  13.                 temp[i] = proRataVolumeFile[i].Split(',');
  14.             }
  15.         }
  16.  
  17.               //convert the string to int
  18.  
  19.         date = new DateTime[temp.Length - 1];
  20.         timeframe = new DateTime[temp[0].Length - 1];
  21.         data = new int[temp.Length - 1][];
  22.  
  23.         for (int i = 1; i < temp.Length; i++)
  24.         {
  25.             data[i - 1] = new int[temp[i].Length - 1];
  26.  
  27.             for (int j = 1; j < temp[i].Length; j++)
  28.             {
  29.                 if (temp[i][j].Length > 0)
  30.                     data[i - 1][j - 1] = Convert.ToInt32(temp[i][j]);
  31.             }
  32.         }
  33.  
  34.         for (int i = 1; i < temp.Length; i++)
  35.         {
  36.             date[i - 1] = Convert.ToDateTime(temp[i][0]);
  37.         }
  38.  
  39.         for (int j = 1; j < temp[0].Length; j++)
  40.         {
  41.             timeframe[j - 1] = DateTime.Parse(temp[0][j]);
  42.         }
  43.     }
  44.    
  45. void SomeMethod<T>(T[] values) where T : IComparable<T>
  46. {
  47.     // Do stuff here
  48. }
  49.    
  50. public static void ReadData<T>(string value, ref T[][] data, ref DateTime[] timeframe, ref DateTime[] date) where T : IConvertible
  51. {
  52.    
  53. dynamic SomeMethod(dynamic[] values)
  54. {
  55.     dynamic result = values[0];
  56.     for (int i = 1; i < values.Length; ++i)
  57.          result = result + values[i]; // You can use normal operators now
  58.     return result;
  59. }
  60.    
  61. static void Swap<T>(ref T lhs, ref T rhs)
  62. {
  63.   T temp;
  64.   temp = lhs;
  65.   lhs = rhs;
  66.   rhs = temp;
  67. }
  68.    
  69. int a = 2;
  70.  int b = 3;
  71.  Swap<int>(ref a, ref b);
  72.    
  73. double a = 2.3;
  74.  double b = 5.7;
  75.  Swap<double>(ref a, ref b);
  76.    
  77. int[] ints = {1, 2, 3 };
  78.     List<int> listInts = ints.ToList();
  79.  
  80.     MyMethod<int>(listInts);
  81.  
  82.     private static void MyMethod<T>(List<T> genericList)
  83.     {
  84.         // do you work
  85.     }
  86.    
  87. public static void ReadDataInt(string value, out int[][] data,
  88.                          out DateTime[] timeframe, out DateTime[] date)
  89.     {
  90.         ReadData(value, out data, out timeframe, out date, Convert.ToInt32);
  91.     }
  92.  
  93.     public static void ReadDataDouble(string value, out double[][] data,
  94.                          out DateTime[] timeframe, out DateTime[] date)
  95.     {
  96.         ReadData(value, out data, out timeframe, out date, Convert.ToDouble);
  97.     }
  98.  
  99.     private static void ReadData<T>(string value, out T[][] data,
  100.                           out DateTime[] timeframe, out DateTime[] date,
  101.                           Func<string, T> converter)
  102.     {
  103.         ...your method goes here with some very minor changes below.
  104.  
  105.         // Generic instead of int/double
  106.         data = new T[temp.Length - 1][];        
  107.         ...
  108.         // Generic instead of int/double
  109.         data[i - 1] = new T[temp[i].Length - 1];
  110.         ...
  111.         // Use a func instead of the hard coded Convert.
  112.         if (temp[i][j].Length > 0)
  113.             data[i - 1][j - 1] = converter(temp[i][j]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top