Mohan J

Mohan J

  • NA
  • 96
  • 31.4k

how to print property name and value of a Class object?

Aug 29 2014 12:43 AM

hi, In C#, I need to print a class field or property name with value without using reflection or string.join method.

For eg.

 protected void Button1_Click(object sender, EventArgs e) 
{ List<EmployeeInfo> obj = new List<EmployeeInfo>();         
obj.Add(new EmployeeInfo { eid = 123 });         
obj.Add(new EmployeeInfo { ename = "abc" }); 
Response.Write(obj.ToString()); // output must be  => ename ="abc" , eid = 123 } 
public class EmployeeInfo 
{ public string ename; 
public int eid; 
}

It need to be resulted as follows automatically with property name and value :

ename ="abc" , eid = 123

It need to be resulted with good performance and simple way.


Answers (1)