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

  • SEARCH
  • Home
  • 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 8595623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:28:48+00:00 2026-06-12T00:28:48+00:00

public static void outputDetail(DateTime previousTime, ref double[] array, StreamWriter streamWriter) //the parameter in here

  • 0
    public static void outputDetail(DateTime previousTime, ref double[] array, StreamWriter streamWriter)  //the parameter in here is not necessary, but want to maintain a similiarity in the TimeOfDay class
    {
        string outputString = previousTime.ToString("yyyy/MM/dd");
        Boolean bypass = true;

        for (int i = 1; i < array.Length - 1; i++)
        {
            outputString = outputString + "," + array[i].ToString();

            if (array[i] != 0)
                bypass = false;
        }
        if (bypass == false)
            streamWriter.WriteLine(outputString);

        for (int i = 0; i < array.Length; i++)
        {
            array[i] = 0;
        }
    }


    public static void outputDetail(DateTime previousTime, ref int[] array, StreamWriter streamWriter)  //the parameter in here is not necessary, but want to maintain a similiarity in the TimeOfDay class
    {
        string outputString = previousTime.ToString("yyyy/MM/dd");
        Boolean bypass = true;

        for (int i = 1; i < array.Length -1; i++)
        {
            if (array[i] != 0)
            {
                outputString = outputString + "," + array[i].ToString();
                bypass = false;
            }
            else
            {
                outputString = outputString + ",";
            }
        }
        if (bypass == false)
            streamWriter.WriteLine(outputString);

        for (int i = 0; i < array.Length; i++)
        {
            array[i] = 0;
        }
    }

they are exactly the same, only one takes a double array and one takes an int array, i see some example use Iconvertible but i cant get the syntax right. can someone post some workable snippet for the method pls?

can how do i call it?

EDIT: thanks very much for the answer, i have another somewhat more complicated case i need to refactor, and the suggestion in here dont work on that 2 methods. Please click this link for more detail

How do I refactor these 2 methods? Part 2.

  • 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-12T00:28:49+00:00Added an answer on June 12, 2026 at 12:28 am

    Change your code to this:

        public static void outputDetail<T>(DateTime previousTime, ref T[] array, System.IO.StreamWriter streamWriter)  //the parameter in here is not necessary, but want to maintain a similiarity in the TimeOfDay class
        {
            string outputString = previousTime.ToString("yyyy/MM/dd");
            Boolean bypass = true;
    
            for (int i = 1; i < array.Length - 1; i++)
            {
                if (!Object.Equals(array[i], default(T)))
                {
                    outputString = outputString + "," + array[i].ToString();
                    bypass = false;
                }
                else
                {
                    outputString = outputString + ",";
                }
            }
            if (bypass == false)
                streamWriter.WriteLine(outputString);
    
            Array.Clear(array, 0, array.Length);
        }
    

    What’s changed?

    First the method signature: it accepts a generic array of type T (so it doesn’t matter if it’s int, double, bool or strings).

    Now you have to fix the comparison for zero. Zero is the default value for both int and double so you can use default(T) to get the default value for actual type and Object.Equals() for comparison (== and != operators aren’t defined for generic types).

    Finally you just have to clear the array (again with zero) so you can simply use Array.Clear() to do all the job (and it’s even little bit faster than a handmade for).

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

Sidebar

Related Questions

public static void Main() { Dictionary<string, double> values = new Dictionary<string, double>(); values.Add(a, 0.002);
public class Demo { public static void main(String args[]) { double d = 12.345;
public static void main(String[] args) throws FileNotFoundException { double agentID; String type; double price;
public class PizzaExamfinalOne{ public static void main(String[]args){ double total2 = 0; String customerName =
public static void WriteLine(string text) { StreamWriter log; if (!File.Exists(Filename)) { log = new
public static void getClientUpdate() { try { String inputLine; double version = 0; URL
public static void Refer(ref int a,ref int b) in this how do i find
public static void main(String[] args) { boolean t=true; System.out.println(Before return); if(t) return; System.out.println(not execute);
public static void main(String[] args) { int i = 0; while(i==0){ System.out.println(Possibilities: R, T,
public static void main(String[] args) { // TODO Auto-generated method stub BufferedReader br1 =

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.