Create an Array of anonymous types in CSharp

Description

The following code shows how to create an Array of anonymous types.

Example


using System;/*from ww w .ja va 2 s. co  m*/
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var curries = new[]
            {
                new { M = "A", S= "C", A = 5 },
                new { M = "B", S= "B", A= 5 },
                new { M = "C", S= "A", A= 5 }
            };
        Console.WriteLine(curries[0].ToString());
        Console.WriteLine(curries[0].GetHashCode());
        Console.WriteLine(curries[1].GetHashCode());
        Console.WriteLine(curries[2].GetHashCode());
        Console.WriteLine(curries[0].Equals(curries[1]));
        Console.WriteLine(curries[0].Equals(curries[2]));
        Console.WriteLine(curries[0] == curries[1]);
        Console.WriteLine(curries[0] == curries[2]);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var