question

Chocolade-4229 avatar image
0 Votes"
Chocolade-4229 asked karenpayneoregon answered

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

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]);
         }

dotnet-csharpwindows-forms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

karenpayneoregon avatar image
1 Vote"
karenpayneoregon answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.