跳轉到內容

NETSquirrel - 指南/低複雜度

來自華夏公益教科書

使用基本型別

[編輯 | 編輯原始碼]

您可以透過NETSquirrel.Utils.BaseTypesUtilsNETSquirrel.Extensions.BaseTypesExtensions 類來讀取所有基本型別的值並對它們進行一些額外的有用操作。 讓我們考慮提供的功能。

從鍵盤讀取基本型別的值

[編輯 | 編輯原始碼]
方法
方法簽名 簡要描述
bool ReadBool(string) 從鍵盤讀取指定提示的bool值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
byte ReadByte(string) 從鍵盤讀取指定提示的byte值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
sbyte ReadSByte(string) 從鍵盤讀取指定提示的sbyte值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
char ReadChar(string) 從鍵盤讀取指定提示的char值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
decimal ReadDecimal(string) 從鍵盤讀取指定提示的decimal值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
double ReadDouble(string) 從鍵盤讀取指定提示的double值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
float ReadFloat(string) 從鍵盤讀取指定提示的float值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
int ReadInt(string) 從鍵盤讀取指定提示的int值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
uint ReadUInt(string) 從鍵盤讀取指定提示的uint值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
long ReadLong(string) 從鍵盤讀取指定提示的long值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
ulong ReadULong(string) 從鍵盤讀取指定提示的ulong值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
short ReadShort(string) 從鍵盤讀取指定提示的short值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
ushort ReadUShort(string) 從鍵盤讀取指定提示的ushort值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。
string ReadString(string) 從鍵盤讀取指定提示的string值並返回它。

引數:

  • prompt = "" - 描述要列印的提示

備註:

  • 如果prompt 為 null,則不輸出任何提示。

方法名稱中使用的總體思路是:ReadTypeName,其中TypeName - 是基本型別的名稱。

ReadBool 用法示例

using NETSquirrel.Extensions;
using NETSquirrel.Utils;

namespace Test
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            BaseTypesUtils.ReadBool("Bool:").PrintLine();
        }
    }
}
{$reference NETSquirrel.dll} 
uses NETSquirrel.Utils;

begin
  BaseTypesUtils.ReadBool('Bool:').PrintLine();
end.

值交換

[編輯 | 編輯原始碼]
方法
方法簽名 簡要描述
void Swap<T>(ref T, ref T) 交換兩個變數的值。

引數:

  • x - 第一個值
  • y - 第二個值

Swap 用法示例

using NETSquirrel.Utils;

namespace Test
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            var x = 1;
            var y = 2;
            BaseTypesUtils.Swap(ref x, ref y); // x == 2, y == 1
        }
    }
}
{$reference NETSquirrel.dll} 
uses NETSquirrel.Utils;

begin
  var x := 1;
  var y := 2;
  BaseTypesUtils.Swap(x, y); // x = 2, y = 1
end.

從特定範圍內生成序列

[編輯 | 編輯原始碼]
擴充套件方法
方法簽名 簡要描述
bool IsBetween(this int, int, int) 評估作為this引數傳遞的值是否介於另外兩個值之間,並返回相應的bool值。

引數:

  • target [this 引數] - 要評估的數字
  • low - 範圍的最低邊界
  • high - 範圍的最高邊界

備註:

  • 範圍邊界lowhigh 參與其中。
IEnumerable<int> To(this int, int) 生成從作為this引數傳遞的值到更高值的序列並返回它。

引數:

  • from [this 引數] - 序列的最低數字
  • to - 序列的最高數字

備註:

  • 範圍邊界fromto 參與其中。
  • 如果to 低於from,則返回空序列。
IEnumerable<int> DownTo(this int, int) 生成從作為this引數傳遞的值到更低值的序列並返回它。

引數:

  • from [this 引數] - 序列的最高數字
  • to - 序列的最低數字

備註:

  • 範圍邊界fromto 參與其中。
  • 如果to 高於from,則返回空序列。
IEnumerable<int> ToThis(this int) 生成從 0 開始向上/向下(取決於第二個值)到作為this引數傳遞的值的序列,並返回它。

引數:

  • to [this 引數] - 最後一個序列號

備註:

  • 範圍邊界 0 和to 參與其中。
IEnumerable<int> Stepped(this int, int) 生成從作為this引數傳遞的值開始的無窮序列,並使用指定的步長返回它。

引數:

  • from [this 引數] - 序列的第一個數字
  • step - 序列的步長

備註:

  • 最低邊界from 參與其中。
bool Print() 輸出bool型別的值。

引數:

  • item [this 引數] - 要列印的值
bool PrintLine() 輸出bool型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
byte Print() 輸出byte型別的值。

引數:

  • item [this 引數] - 要列印的值
byte PrintLine() 輸出byte型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
sbyte Print() 輸出sbyte型別的值。

引數:

  • item [this 引數] - 要列印的值
sbyte PrintLine() 輸出sbyte型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
char Print() 輸出char型別的值。

引數:

  • item [this 引數] - 要列印的值
char PrintLine() 輸出char型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
decimal Print() 輸出decimal型別的值。

引數:

  • item [this 引數] - 要列印的值
decimal PrintLine() 輸出decimal型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
double Print() 輸出double型別的值。

引數:

  • item [this 引數] - 要列印的值
double PrintLine() 輸出double型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
float Print() 輸出float型別的值。

引數:

  • item [this 引數] - 要列印的值
float PrintLine() 輸出float型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
int Print() 輸出int型別的值。

引數:

  • item [this 引數] - 要列印的值
int PrintLine() 輸出int型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
uint Print() 輸出uint型別的值。

引數:

  • item [this 引數] - 要列印的值
uint PrintLine() 輸出uint型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
long Print() 輸出long型別的值。

引數:

  • item [this 引數] - 要列印的值
long PrintLine() 輸出long型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
ulong Print() 輸出ulong型別的值。

引數:

  • item [this 引數] - 要列印的值
ulong PrintLine() 輸出ulong型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
short Print() 輸出short型別的值。

引數:

  • item [this 引數] - 要列印的值
short PrintLine() 輸出short型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值
ushort Print() 輸出ushort型別的值。

引數:

  • item [this 引數] - 要列印的值
ushort PrintLine() 輸出ushort型別的值,並跳到新的一行。

引數:

  • item [this 引數] - 要列印的值

To, DownToToThis 用法示例

using NETSquirrel.Extensions;

namespace Test
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            1.To(10).PrintLine(); // 1, 2, ..., 10
            10.DownTo(1).PrintLine(); // 10, 9, ..., 1
            10.ToThis().PrintLine(); // 0, 1, ..., 10
        }
    }
}
{$reference NETSquirrel.dll} 

begin
  1.To(10).PrintLine(); // 1, 2, ..., 10
  10.DownTo(1).PrintLine(); // 1, 2, ..., 10
  10.ToThis().PrintLine(); // 1, 2, ..., 10
end.

使用陣列

[編輯 | 編輯原始碼]

您可以透過NETSquirrel.Utils.ArrayUtils 類來讀取所有基本型別的陣列並對它們進行一些額外的有用操作。 讓我們考慮提供的功能。

陣列生成器

[編輯 | 編輯原始碼]
方法
方法簽名 簡要描述
T[] GenerateArray<T>(int, Func<int, T>, int) 使用特定選擇器生成指定長度的陣列並返回它。

引數:

  • count - 陣列的長度
  • selector - 將每個索引投影到某個值的委託例項
  • firstIndex - 索引偏移

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果selector 為 null,則丟擲ArgumentNullException

備註:

  • 每個索引i 從 0..count 範圍內對映到具體的第 i 個值。
T[] GenerateArray<T>(int, T, Func<T, T>) 使用特定選擇器生成指定長度的陣列並返回它。

引數:

  • count - 陣列的長度
  • first - 陣列的第一個值
  • selector - 從前一個值檢索下一個值的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果next 為 null,則丟擲ArgumentNullException
T[] GenerateArray<T>(int, Func<T[], int, T>) 使用特定選擇器生成指定長度的陣列並返回它。

引數:

  • count - 陣列的長度
  • selector - 根據前一個值檢索下一個值的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果selector 為 null,則丟擲ArgumentNullException

備註:

  • 委託的陣列(第一個)引數用於引用正在建立的陣列。
  • 委託的索引(第二個)引數用於引用要設定的第 i 個值。
int[] CreateRandomIntArray(int, int, int) 建立隨機填充的陣列,其中值取自特定範圍。

引數:

  • count - 陣列的長度
  • low [可選引數],預設值 = 0 - 確定最低範圍的邊界
  • high [可選引數],預設值 = int.MaxValue - 確定最高範圍的邊界

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 low > high,則丟擲 ArgumentOutOfRangeException
float[] CreateRandomFloatArray(int, float, float) 建立隨機填充的陣列,其中值取自特定範圍。

引數:

  • count - 陣列的長度
  • low [可選引數],預設值 = 0 - 確定最低範圍的邊界
  • high [可選引數],預設值 = float.MaxValue - 確定最高範圍的邊界

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 low > high,則丟擲 ArgumentOutOfRangeException

GenerateArray 用法示例

using NETSquirrel.Extensions;
using NETSquirrel.Utils;

namespace Test
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            ArraysUtils.GenerateArray(10, i => i).PrintLine(); // 0, 1, ..., 10
            ArraysUtils.GenerateArray(10, 0, x => x + 1).PrintLine(); // 0, 1, ..., 10
        }
    }
}
{$reference NETSquirrel.dll} 
uses NETSquirrel.Utils;

begin
  ArraysUtils.GenerateArray(10, i -> i).PrintLine(); // 0, 1, ..., 10
  ArraysUtils.GenerateArray(10, 0, x -> x + 1).PrintLine(); // 0, 1, ..., 10
end.

GenerateArray 用法示例 2

using NETSquirrel.Extensions;
using NETSquirrel.Utils;

namespace Test
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            ArraysUtils.GenerateArray<int>(10, (array, i) => {
                switch (i)
                {
                    case 0:
                    case 1:
                        return 1;
                    default:
                        return array[i - 1] + array[i - 2];
                }
            }).PrintLine(); // 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
        }
    }
}
{$reference NETSquirrel.dll} 
uses NETSquirrel.Utils;
 
begin
  ArraysUtils.GenerateArray&<integer>(10, (a, i) -> begin
    case i of
      0, 1: Result := 1;
      else Result := a[i - 1] + a[i - 2];
    end;
  end).PrintLine(); // 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
end.

從鍵盤讀取陣列

[編輯 | 編輯原始碼]
方法名稱 簡要描述
bool[] ReadBoolArray(int, string) 讀取指定長度的 bool[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
bool[] ReadBoolArray(int, Func<int, string>) 讀取指定長度的 bool[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
bool[] ReadBoolArray(int, ExceptionHandler, string) 讀取指定長度的 bool[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
bool[] ReadBoolArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 bool[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
byte[] ReadByteArray(int, string) 讀取指定長度的 byte[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
byte[] ReadByteArray(int, Func<int, string>) 讀取指定長度的 byte[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
byte[] ReadByteArray(int, ExceptionHandler, string) 讀取指定長度的 byte[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
byte[] ReadByteArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 byte[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
sbyte[] ReadSByteArray(int, string) 讀取指定長度的 sbyte[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
sbyte[] ReadSByteArray(int, Func<int, string>) 讀取指定長度的 sbyte[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
sbyte[] ReadSByteArray(int, ExceptionHandler, string) 讀取指定長度的 sbyte[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
sbyte[] ReadSByteArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 sbyte[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
char[] ReadCharArray(int, string) 讀取指定長度的 char[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
char[] ReadCharArray(int, Func<int, string>) 讀取指定長度的 char[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
decimal[] ReadDecimalArray(int, string) 讀取指定長度的 decimal[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
decimal[] ReadDecimalArray(int, Func<int, string>) 讀取指定長度的 decimal[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
decimal[] ReadDecimalArray(int, ExceptionHandler, string) 讀取指定長度的 decimal[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
decimal[] ReadDecimalArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 decimal[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
double[] ReadDooubleArray(int, string) 讀取指定長度的 double[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
double[] ReadDooubleArray(int, Func<int, string>) 讀取指定長度的 double[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
double[] ReadDooubleArray(int, ExceptionHandler, string) 讀取指定長度的 double[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
double[] ReadDooubleArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 double[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
float[] ReadFloatArray(int, string) 讀取指定長度的 float[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
float[] ReadFloatArray(int, Func<int, string>) 讀取指定長度的 float[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
float[] ReadFloatArray(int, ExceptionHandler, string) 讀取指定長度的 float[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
float[] ReadFloatArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 float[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
int[] ReadIntArray(int, string) 讀取指定長度的 int[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
int[] ReadIntArray(int, Func<int, string>) 讀取指定長度的 int[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
int[] ReadIntArray(int, ExceptionHandler, string) 讀取指定長度的 int[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
int[] ReadIntArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 int[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
uint[] ReadUIntArray(int, string) 讀取指定長度的 uint[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
uint[] ReadUIntArray(int, Func<int, string>) 讀取指定長度的 uint[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
uint[] ReadUIntArray(int, ExceptionHandler, string) 讀取指定長度的 uint[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
uint[] ReadUIntArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 uint[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
long[] ReadLongArray(int, string) 讀取指定長度的 long[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
long[] ReadLongArray(int, Func<int, string>) 讀取指定長度的 long[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
long[] ReadLongArray(int, ExceptionHandler, string) 讀取指定長度的 long[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
long[] ReadLongArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 long[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
ulong[] ReadULongArray(int, string) 讀取指定長度的 ulong[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
ulong[] ReadULongArray(int, Func<int, string>) 讀取指定長度的 ulong[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
ulong[] ReadULongArray(int, ExceptionHandler, string) 讀取指定長度的 ulong[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
ulong[] ReadULongArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 ulong[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
short[] ReadShortArray(int, string) 讀取指定長度的 short[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
short[] ReadShortArray(int, Func<int, string>) 讀取指定長度的 short[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
short[] ReadShortArray(int, ExceptionHandler, string) 讀取指定長度的 short[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
short[] ReadShortArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 short[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
ushort[] ReadUShortArray(int, string) 讀取指定長度的 ushort[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
ushort[] ReadUShortArray(int, Func<int, string>) 讀取指定長度的 ushort[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
ushort[] ReadUShortArray(int, ExceptionHandler, string) 讀取指定長度的 ushort[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
ushort[] ReadUShortArray(int, ExceptionHandler, Func<int, string>) 讀取指定長度的 ushort[] 型別陣列。

引數:

  • count - 陣列的長度
  • handler - 異常的處理程式
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
  • 如果 handler 為 null,則不會處理發生的異常。
string[] ReadStringArray(int, string) 讀取指定長度的 string[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat = "item {0}:" - 提示的格式

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。
string[] ReadStringArray(int, Func<int, string>) 讀取指定長度的 string[] 型別陣列。

引數:

  • count - 陣列的長度
  • promptFormat - 指定每個陣列項的提示格式的委託例項

異常:

  • 如果count < 0,則丟擲ArgumentOutOfRangeException
  • 如果 promptFormat 為 null,則丟擲 ArgumentNullException

備註:

  • promptFormat 引數用於讀取每個陣列項。

ReadBoolArray 用法示例

using NETSquirrel.Extensions;
using NETSquirrel.Utils;

namespace Test
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            ArraysUtils.ReadBoolArray(10, "item {0} = ").PrintLine();
            ArraysUtils.ReadBoolArray(10, i => $"{new[] { "even", "odd" }[i % 2]} item = ").PrintLine();
        }
    }
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
 
begin
  ArraysUtils.ReadBoolArray(10, 'item {0} = ').PrintLine();
  var lambda: integer -> string := i -> string.Format('{0} item = ', (new string[] ('even', 'odd'))[i mod 2]);
  ArraysUtils.ReadBoolArray(10, lambda).PrintLine();
end.

ReadBoolArray 用法示例 2

using NETSquirrel.Extensions;
using NETSquirrel.Utils;

namespace Test
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            ArraysUtils.ReadBoolArray(10, e => e.Message.PrintLine(), "item {0} = ").PrintLine();
            ArraysUtils.ReadBoolArray(10, e => e.Message.PrintLine(),
                i => $"{new[] { "even", "odd" }[i % 2]} item = ").PrintLine();
        }
    }
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
uses NETSquirrel;
 
begin
  ArraysUtils.ReadBoolArray(10, procedure(e) -> e.Message.PrintLine(), 'item {0} = ').PrintLine();
  ArraysUtils.ReadBoolArray(10, procedure(e) -> e.Message.PrintLine(),
    i -> string.Format('{0} item = ', (new string[] ('even', 'odd'))[i mod 2])).PrintLine();
end.

處理矩陣

[編輯 | 編輯原始碼]

矩陣生成器

[編輯 | 編輯原始碼]

從鍵盤讀取矩陣

[編輯 | 編輯原始碼]
華夏公益教科書