tagged [anonymous-types]

LINQ How to select more than 1 property in a lambda expression?

LINQ How to select more than 1 property in a lambda expression? We often use the following lambda expression Is possible to get more than 1 property usinglambda expression ? E.g `Id` and `Name` from M...

24 May at 20:8

How to pass anonymous types as parameters?

How to pass anonymous types as parameters? How can I pass anonymous types as parameters to other functions? Consider this example: The variable `query` here doesn't have strong type. How should I defi...

Is there a way to create anonymous structs in C#?

Is there a way to create anonymous structs in C#? There doesn't seem to be any way as anonymous types derive from object. But I thought I'd ask since much of the time we use anonymous types in simple ...

15 Feb at 16:27

Why does Enum.GetValues() return names when using "var"?

Why does Enum.GetValues() return names when using "var"? Can anyone explain this? [alt text http://www.deviantsart.com/upload/g4knqc.png](http://www.deviantsart.com/upload/g4knqc.png) ``` using System...

9 Jul at 14:13

Create Generic Class instance based on Anonymous Type

Create Generic Class instance based on Anonymous Type I have a class `ReportingComponent`, which has the constructor: I have Linq Query against the Northwind Database, Query is of type `IQueryable

11 Nov at 07:28

C# and arrays of anonymous objects

C# and arrays of anonymous objects What does such an expression mean? ``` obj.DataSource = new[] { new {Text = "Silverlight", Count = 10, Link="/Tags/Silverlight" }, new {Text = "IIS 7", Count = 1...

16 Mar at 04:36

A generic list of anonymous class

A generic list of anonymous class In C# 3.0 you can create anonymous class with the following syntax Is there a way to add these anonymous class to a generic list? Example: Another Example: ``` Lis

6 Sep at 20:39

How to use Expression to build an Anonymous Type?

How to use Expression to build an Anonymous Type? In C# 3.0 you can use Expression to create a class with the following syntax: But how do you use Expression to create an Anonymous class? ``` //anonym...

C# anonymously implement interface (or abstract class)

C# anonymously implement interface (or abstract class) In Java it is possible to extend an interface with an anonymous class that you can implement on the fly. Example: (More on: [http://www.techartif...

20 Jan at 12:34

C# 7.0 ValueTuples vs Anonymous Types

C# 7.0 ValueTuples vs Anonymous Types Looking at the new C# 7.0 ValueTuples, I am wondering if they will completely replace `Anonymous Types`. I understand that `ValueTuples` are structs and therefore...

12 Apr at 07:47

Resolving a parameter name at runtime

Resolving a parameter name at runtime > [Finding the Variable Name passed to a Function in C#](https://stackoverflow.com/questions/72121/finding-the-variable-name-passed-to-a-function-in-c-sharp) In...

23 May at 12:14

IQueryable for Anonymous Types

IQueryable for Anonymous Types I use EntityFramework, I'm querying and returning partial data using Anonymous Types. Currently I'm using `IQueryable`, it works, but I would like to know if this is the...

26 Oct at 10:30

deserialize json into list of anonymous type

deserialize json into list of anonymous type I have a json as below : now I want to deserilize this into a list of objects of anonymous type "foo" the code is : ``` ServiceStackJsonSerializer Jseriali...

Anonymous Types C#

Anonymous Types C# I understand that anonymous types have no pre-defined type of its own. Type is assigned to it by the compiler at the compile type and details of type assigned at compile time can't ...

27 May at 09:47

Using ServiceStack.Text to deserialize a json string to object

Using ServiceStack.Text to deserialize a json string to object I have a JSON string that looks like: I'm trying to deserialize it to `object` (I'm implementing a caching interface) The trouble I'm hav...

Add item to an anonymous list

Add item to an anonymous list I have a list of anonymous type And I want to add an other item to this list like I also tried ``` myList.Add(new { "--All--", 0, 0}); //Error: Has some invalid arguments...

14 May at 10:57

How do I declare "Key" fields in C# anonymous types?

How do I declare "Key" fields in C# anonymous types? In VB.NET I'm used to doing things like this when creating anonymous types ([VB.NET anonymous types include the notion of Key Fields](http://msdn.m...

21 Jan at 02:25

LINQ Select Distinct with Anonymous Types

LINQ Select Distinct with Anonymous Types So I have a collection of objects. The exact type isn't important. From it I want to extract all the unique pairs of a pair of particular properties, thusly: ...

Declaring an anonymous type member with a simple name

Declaring an anonymous type member with a simple name When you try to compile this: You will get the compiler error because the compiler is not able to infer the name of the properties from the respec...

27 Oct at 15:28

Return/consume dynamic anonymous type across assembly boundaries

Return/consume dynamic anonymous type across assembly boundaries The code below works great. If the `Get` and `Use` methods are in different assemblies, the code fails with a RuntimeBinderException. T...

8 Jan at 03:55

Get read/write properties of Anonymous Type

Get read/write properties of Anonymous Type I need to fetch all the properties of an anonymous type which can be written to. eg: The problem is that all the properties have their `CanWrite` property

14 Jul at 19:47

Storing an Anonymous Object in ViewBag

Storing an Anonymous Object in ViewBag This is probably a silly question, but I am trying to stuff an anonymous object in `ViewBag` like so: and access it from a View like so: @ViewBag.Stuff.Name I u...

Anonymous Types in C#

Anonymous Types in C# but `ano` object's properties created are read-only . I want to figure it out why those properties are read only. suggestions are

24 Dec at 00:27

how to map an anonymous object to a class by AutoMapper?

how to map an anonymous object to a class by AutoMapper? I have an entity: and a model: ``` public class TagModel { public int Id { get; set; } public string Word { get; set;

Are C# anonymous types redundant in C# 7

Are C# anonymous types redundant in C# 7 Since C# 7 introduces value tuples, is there a meaningful scenario where they are better suited than tuples? For example, the following line makes the followin...