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:

How to Install and Use RTSP Simple Server

  How to Install and Use RTSP Simple Server   1.   Create a folder to store the app mkdir /etc/rtsp-server cd /etc/rtsp-server   2.  Downloa...