Thursday, May 24, 2012

Convert Anonymous Type into key/value Array

The answer in this link is very simple and great:

http://stackoverflow.com/questions/3481923/in-c-sharp-convert-anonymous-type-into-key-value-array


var a = new { data1 = "test1", data2 = "sam", data3 = "bob" };
var type = a.GetType();
var props = type.GetProperties();
var pairs = props.Select(x => x.Name + "=" + x.GetValue(a, null)).ToArray();
var result = string.Join("&", pairs);

No comments:

Running Proxmox Inside Hyper-V on Windows 11: Nested Virtualization Lab Setup

I have a good PC at home with an Intel i9 12th Gen processor, 96GB RAM, and 1TB of unused disk storage. It’s our family PC for everyday use,...