C# 中的混合陣列是什麼?
混合陣列是多維陣列和參差陣列的組合。
注意 − 自從 .NET 4.0 更新刪除後,混合陣列型別現已過時。
讓我們瞭解如何宣告混合陣列 −
var x = new object[] {89,45,"jacob",9.8}
我們還可以將其設定為 −
var x = new object[] {87, 33,"tim",6.7, new List<string>() {"football","tennis","squash",“cricket”} }
因為混合陣列現已過時。對於相同的工作,請使用列表集合。在此,我們在列表中設定了 int 和 string −
Tuple<int, string> tuple = new Tuple<int, string>(60, "John");
下面顯示相同的示例
using System; using System.Collections.Generic; class Program { static void Main() { // Initializing collections Tuple tuple = new Tuple(99, "Jack"); if (t.Item1 == 99) { Console.WriteLine(tuple.Item1); } } }
廣告