0% found this document useful (0 votes)
14 views

ASM Anonymous Types

The document describes an anonymous type class called Product that contains properties for ProductID, ProductName, UnitPrice, and Quantity. An instance of the anonymous type is created and assigned to the variable "product" with sample values. The property values of the product variable are then outputted to the console. Attempting to modify the Quantity property results in an error, as anonymous types are read-only.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

ASM Anonymous Types

The document describes an anonymous type class called Product that contains properties for ProductID, ProductName, UnitPrice, and Quantity. An instance of the anonymous type is created and assigned to the variable "product" with sample values. The property values of the product variable are then outputted to the console. Attempting to modify the Quantity property results in an error, as anonymous types are read-only.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Sword Lake

Anonymous Types Create a Console Application that have a class Product as the following :
namespace Anonymous_types { class Program { static void Main(string[] args) { var product = new { ProductID = "P001", ProductName = "Coffee", UnitPrice = 10.5f, Quantity = 5 }; Console.WriteLine("ProductID = {0}", product.ProductID); Console.WriteLine("ProductName = {0}" , product.ProductName); Console.WriteLine("UnitPrice = {0}", product.UnitPrice); Console.WriteLine("Quantity = {0}", product.Quantity); //Console.WriteLine("Change Quantity to 20 "); //product.Quantity = 20; //error : read only Console.ReadLine(); } }

You might also like