How can i extend a method to return array of strings instead one single string ?

Chocolade 536 Reputation points
2022-05-02T23:51:45.55+00:00

This method return string but let's say i want to convert two variables of sizes using this method. for example :

var newSize = info.Length;
var oldsize = dic[e.FullPath];
var size = SizeSuffix(newSize);
 var oldies = SizeSuffix(oldsize);

but instead making each time a new variable maybe it will be better to do something like :

var Sizes = SizeSuffix(newSize, oldsize);

and if i want to add more for example

var Sizes = SizeSuffix(newSize, oldsize, t1, t2, t3);

and then using it like :

Sizes[0] and Sizes[1]....and so on.

static string SizeSuffix(Int64 value)
        {
            if (value < 0) { return "-" + SizeSuffix(-value); }

            int i = 0;
            decimal dValue = (decimal)value;
            while (Math.Round(dValue / 1024) >= 1)
            {
                dValue /= 1024;
                i++;
            }

            return string.Format("{0:n1} {1}", dValue, SizeSuffixes[i]);
        }
Developer technologies Windows Forms
Developer technologies C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2022-05-03T00:37:24.817+00:00

    Look at use a param array for passing same type parameters to your method then return the array of strings or perhaps a list of string.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.