----------------------------------------------主程序
目前創(chuàng)新互聯(lián)已為成百上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站托管、服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、張灣網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
//自定義格式化字符串
Voctor v = new Voctor(3d, 4d, 5d);
Console.WriteLine("{0:zhang}", v);//Zhang:(3,4,5)
Console.WriteLine("{0:liu}", v);//Liu:(3,4,5)
Console.ReadKey();
}
}
}----------------------------------------------Voctor.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
//自定義格式化字符串類或結(jié)構(gòu)必須實(shí)現(xiàn)IFormattable接口
public class Voctor : IFormattable
{
double x, y, z;
public Voctor(double d1, double d2, double d3)
{
this.x = d1;
this.y = d2;
this.z = d3;
}
//format表示傳遞的說明符,例如N(不用考慮formatProvider)
public string ToString(string format, IFormatProvider formatProvider)
{
if (format == null)
{
return ToString();
}
//不區(qū)分大小寫
string formatUpper = format.ToUpper();
switch (formatUpper)
{
case "ZHANG":
return "Zhang:" + ToString();
case "LIU":
return "Liu:" + ToString();
default:
return ToString();
}
}
public override string ToString()
{
return string.Format("({0},{1},{2})", x, y, z);
}
}
}


網(wǎng)頁名稱:自定義格式化字符串
分享URL:http://www.chinadenli.net/article24/gccgje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站營銷、動(dòng)態(tài)網(wǎng)站、建站公司、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)