登录 注册
当前位置:主页 > 资源下载 > 31 > 入门经典教程:C#定制ToString方法

入门经典教程:C#定制ToString方法

  • 更新:2024-06-22 15:14:38
  • 大小:4.81MB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:.Net - 课程资源
  • 格式:PPT

资源介绍

定制ToString() 默认返回. 定制ToString方法实例: using System.Text; using System; public class Chair { private double myPrice; private string myVendor, myID; public Chair(double price, string vendor, string sku) { myPrice = price; myVendor = vendor; myID = sku; } public override string ToString() { StringBuilder chairSB = new StringBuilder(); chairSB.AppendFormat("ITEM = Chair"); chairSB.AppendFormat("\tVENDOR = {0}", myVendor); chairSB.AppendFormat("\tPRICE = {0}", myPrice.ToString()); return chairSB.ToString(); } static void Main() { Chair myChair = new Chair(120.0, "Broyhill", "60-1222"); Console.WriteLine(myChair.ToString()); } }