什么是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() {
      //初始化集合
      Tuple tuple = new Tuple(99, "Jack");
      if (t.Item1 == 99) {
         Console.WriteLine(tuple.Item1);
      }
   }
}