所以我试图将一个长数组转换为反向长数组。这就是我所拥有的:
public static long[] Digitize(long n)
{
string numConvert = n.ToString();
char[] charArray = numConvert.ToCharArray();
long[] charToLong = new long[charArray.Length];
for (int i = 0; i < charArray.Length; i++)
charToLong[i] = Convert.ToInt64(charArray[i]);
return Array.Reverse(charToLong);
}
但每次编译时,我都会收到此错误:&#34;无法隐式转换类型&#39; void&#39;到[&#39; long []&#39;&#34; 我刚才在这做什么?
答案 0 :(得分:2)
Array.Reverse(charToLong);
return charToLong;
Array.Reverse返回void,而不是反转数组。点击该链接,然后查看语法:public static void
。
答案 1 :(得分:2)
您需要返回数组,而不是函数。
Option Explicit
Sub deleteCells()
Dim rng As Range, str As String
On Error Resume Next
str = "Item"
With Worksheets("sheet1")
Set rng = .Cells.Find(str)
Do While Not rng Is Nothing
rng.Resize(2, 2).Delete Shift:=xlUp
Set rng = .Cells.Find(str)
Loop
End With
End Sub
不返回任何内容(Array.Reverse()
),因此在调用void
后,您需要返回数组:
Array.Reverse(charToLong;)
答案 2 :(得分:2)
只需在字符串上调用Reverse
,然后将每个字符转回long
并返回。
public static long[] Digitize(long n)
{
var reversed = n.ToString().Reverse().Select(x => long.Parse(x.ToString())).ToArray();
return reversed;
}