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”} }

由於現在混合陣列已過時。對於相同的工作,請使用 List 集合。我們在這裡在列表中設定了 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);
      }
   }
}

更新於: 20-6 月-2020

871 次瀏覽

開啟你的職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.