More
Image
Convert Class to string
By JC.Adinarayana Reddy On 20 Dec 2016
Categories: C#.net
In order to convert a class into a string you need to override the ToString() method.


public class AuthUser
{


   public int UserID { get; set; }
   public string UserNo { get; set; }
   public string UserName { get; set; }
   public string Password { get; set; }

   public override string ToString()
   {
     return UserID + "," + UserNo + "," + UserName + "," + Password;
   }

}

Below code will give you a comma separated string output.

AuthUser au = new AuthUser { UserID=1, UserNo="001", UserName="adi", Password="123"};
Response.Write(au.ToString());

Output:
1,001,adi,123

 


Comments
Message :
Comments
JC.Adinarayana Reddy
.net
.net