Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:39:47+00:00 2026-06-11T23:39:47+00:00

This is the part 2 of my refactor problem. I have successfully refactor my

  • 0

This is the part 2 of my refactor problem. I have successfully refactor my previous method in here:

how do i refactor these 2 methods?

The second part is similar, however I am unable to successfully refactor this 2 methods. When using a generic method, I was stuck at the line:

temp = (T)Convert.ToInt(value); 

So somehow I need a different approach to refactor these 2 methods.

public static void readDataDouble(string value, ref double[][] 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(',');
        }
    }
    date = new DateTime[temp.Length - 1];
    timeframe = new DateTime[temp[0].Length - 1];
    data = new double[temp.Length - 1][];

    for (int i = 1; i < temp.Length; i++)
    {
        data[i - 1] = new double[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.ToDouble(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]);
    }
}

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] = DateTime.Parse(temp[i][0]);
    }

    for (int j = 1; j < temp[0].Length; j++)
    {
        timeframe[j - 1] = DateTime.Parse(temp[0][j]);
    }
}

I’d appreciate if someone post some working snippet to this problem and how can i call it.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:39:48+00:00Added an answer on June 11, 2026 at 11:39 pm

    You can use generics again:

        public static void readDataInt<T>(string value, ref T[][] 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(',');
                }
            }
    
            date = new DateTime[temp.Length - 1];
            timeframe = new DateTime[temp[0].Length - 1];
            data = new T[temp.Length - 1][];
    
            for (int i = 1; i < temp.Length; i++)
            {
                data[i - 1] = new T[temp[i].Length - 1];
    
                for (int j = 1; j < temp[i].Length; j++)
                {
                    if (temp[i][j].Length > 0)
                        data[i - 1][j - 1] = (T)((IConvertible)temp[i][j]).ToType(typeof(T),
                            System.Globalization.CultureInfo.InvariantCulture);
                }
            }
    
            for (int i = 1; i < temp.Length; i++)
            {
                date[i - 1] = DateTime.Parse(temp[i][0]);
            }
    
            for (int j = 1; j < temp[0].Length; j++)
            {
                timeframe[j - 1] = DateTime.Parse(temp[0][j]);
            }
        }
    

    Again you have to change strongly typed array to its generic counterpart, besides this the only notable change is the line where the conversion occurs. Because string implements IConvertible you can use IConvertible.ToType() method to convert it to any other (supported) type. Conversions to primitive types are supported, for less trivial conversions you may consider to use a conversion library like Universal Type Converter. Please note that now the conversion needs an IFormatProvider (doubles, for example, are represented in different ways for different cultures).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This part of an app that I am working on, I have the following
I have this part of script from my GAE application which uses webapp2, which
I added this part of the code in my onCreate() method and it crashes
I have two very similar methods in Grails, something like calculate statistics by os
I have this C# class structure that I would like to refactor to use
I was given a weird task. I have to refactor certain methods in a
I have been trying to refactor a LINQ expression into a method, and have
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
This part of my code is used to award a grade to a student
Considering this part of a Java class, private List<Object> components = new ArrayList<Object>(); private

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.