---
title: "Anonymous in C#"  
description: "In this blog, I’m explaining about Anonymous in C#  What is Anonymous?Anonymous types allow us to create a new type without defining them. This is a w"  
author: "priyanka kushwaha"  
published: 2015-03-10  
updated: 2018-02-22  
canonical: https://www.mindstick.com/blog/831/anonymous-in-c-sharp  
category: ".net"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Anonymous in C#

In this blog, I’m explaining about Anonymous in C#

##### \

##### What is Anonymous?

Anonymous types allow us to create a new type without defining them. This is a way of defining read-only [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) into a single object without having to [define](https://yourviews.mindstick.com/audio/1110/lifestyles-choices-that-define-our-lives) type explicitly.

[Restrictions](https://www.mindstick.com/news/2343/a-handbook-for-social-media-parental-restrictions) of Anonymous Type class

- [Anonymous class](https://www.mindstick.com/blog/11108/nested-classes-in-java-anonymous-classes) can contain only [public](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) [fields](https://www.mindstick.com/interview/23496/what-are-tables-and-fields).
- Anonymous class’s fields must all be initialized.
- Anonymous class member never is [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods).
- Anonymous cannot implement the interface.

##### Example:

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;delegate void NumberChanger(int n); namespace AnonTypes{    class Program    {        static int num = 10;        public static void AddNum(int p)        {            num += p;            Console.WriteLine("Name method:{0}", num);        }        static void Main(string[] args)        {            var p = new { Name = "Avon", Price = "3000" };            Console.WriteLine("Name={0}\n price={1}", p.Name, p.Price);            //Anonymous methods             NumberChanger nc = delegate(int x)            {                Console.WriteLine("Anonymous method:{0}", x);            };            nc(10);                   }    }}
```

**[Output](https://www.mindstick.com/forum/161319/how-does-the-print-function-handle-output-in-python):**\

**\**

Name=Avon

Price=3000

Anonymous [method](https://www.mindstick.com/forum/166/webservice-method)=10

---

Original Source: https://www.mindstick.com/blog/831/anonymous-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
