我有一個HelperFunctions課程,其中包含很多我的作業方法。其中一個函式就是簡單地列印陣列的內容:
internal static void printArray(T[] arr)
{
foreach (var item in arr)
{
System.Console.WriteLine(item);
}
}
這里的問題是printArray類中唯一HelperFunctions需要型別引數的函式。因此,任何其他函式呼叫都需要隨機型別。
例子:
System.Console.WriteLine("\n" "Result of challenge 1: " HelperFunctions<int>.printB64Res(ch1.hexToB64()));
byte[] input1 = HelperFunctions<int>.ProperHex(this.text1);
byte[] input2 = HelperFunctions<int>.ProperHex(this.text2);
HelperFunctions<string>.printArray(HelperFunctions<int>.readFile(dir @"\hashes.txt"));
// printArray() is the only function which needs a type argument
這里有什么更好的選擇?
uj5u.com熱心網友回復:
試試這個,用這個
internal static void printArray<T>(T[] arr)
{
foreach (var item in arr)
{
System.Console.WriteLine(item);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/350509.html
