定制ToString-C#教程实用版 ppt

时间:2024-05-13 13:33:32
【文件属性】:

文件名称:定制ToString-C#教程实用版 ppt

文件大小:4.81MB

文件格式:PPT

更新时间:2024-05-13 13:33:32

C#教程实用版 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()); } }


网友评论