(){"football","tennis",&quo"/> (){"football","tennis",&quo">

首頁  >  文章  >  後端開發  >  在C#中,什麼是混合數組?

在C#中,什麼是混合數組?

WBOY
WBOY轉載
2023-08-23 08:49:34682瀏覽

在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",&ldquo;cricket&rdquo;} }

由於混合數組現在已經過時。對於相同的工作,請使用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);
      }
   }
}

以上是在C#中,什麼是混合數組?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除