2

I want to create a new type using anonymous types.

This is my code:

 var t = paramaterList.Select(x => x).ToArray().Select(item => new
             {
                 item,
             });

I need to create properties for var t based on the name of item.

For example:

if paramaterList.Select(x => x).ToArray() contained 3 items: FirstName, Surname, Age

This should create properties for each of those items:

paramaterList.Select(x => x).ToArray().Select(item => new
             {

             });
Tân
  • 1
  • 15
  • 56
  • 102
John
  • 263
  • 1
  • 15

1 Answers1

0

Anonymous types are still statically typed, even though they don't have a name that you can use to refer to them by. If you don't know the fields that this object is going to have at compile time, then you can't create a variable of an anonymous type to hold that data. You'll need to store the data in some form of data structure, such as a dictionary, that doesn't require you to know what the values are at compile time.

Servy
  • 202,030
  • 26
  • 332
  • 449