Create Anonymous Type in CSharp

Description

The following code shows how to create Anonymous Type.

Example


   /*w ww .j av  a2 s.com*/

using System;
using System.ComponentModel;

    class MainClass
    {
        static void Main()
        {
            var tom = new { Name = "Tom", Age = 4 };
            var holly = new { Name = "Holly", Age = 31 };
            var jon = new { Name = "Jon", Age = 31 };

            Console.WriteLine("{0} is {1} years old", jon.Name, jon.Age);
        }
    }

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