实现自定义IFormattable
来源:互联网 发布:爱壁纸hd for mac 编辑:程序博客网 时间:2024/04/28 05:02
using System;using System.Collections;using System.Linq;using System.Text;using System.Collections.Generic;using System.Runtime.Serialization;namespace TestCS{ //实现IFormattable struct Vector:IFormattable { public double x, y, z; public Vector(double a, double b, double c) { x = a; y = b; z = c; } #region IFormattable 成员 public string ToString(string format, IFormatProvider formatProvider) { switch (format.ToUpper()) { case "N": return "||" + Norm().ToString() + "||"; case "VE": return string.Format("{0:E},{1:E},{2:E}", x, y, z); case "IJK": StringBuilder sb = new StringBuilder(x.ToString(), 30); sb.AppendFormat(" i + "); sb.AppendFormat(y.ToString()); sb.AppendFormat(" j + "); sb.AppendFormat(z.ToString()); sb.AppendFormat(" k"); return sb.ToString(); default: return ToString(); } } private double Norm() { return x * x + y * y + z * z; } #endregion } public class Progarm { public static void Main(string[] args) { //IFormatProvider表示要显示的变量 Vector v1 = new Vector(2.3, 44.24, -33.3); Console.WriteLine("{0:N}", v1); Console.WriteLine("{0:ve}", v1); Console.WriteLine("{0:ijk}", v1); Console.ReadLine(); } } }
- 实现自定义IFormattable
- 使用IFormattable实现自定义格式字符串输出
- C# IFormattable接口,实现自定义的字符串格式化方法
- 自定义ToString(),实现IFormattable.ToString()及IFormatProvider接口
- ToString IFormattable 自定义格式化
- C# 自定义格式字符串随笔(IFormattable,IFormatProvider,ICustomFormatter三接口的实现)
- 自定义格式字符串随笔(IFormattable,IFormatProvider,ICustomFormatter三接口的实现)
- C# 自定义格式字符串随笔(IFormattable,IFormatProvider,ICustomFormatter三接口的实现)
- C# 自定义格式字符串随笔(IFormattable,IFormatProvider,ICustomFormatter三接口的实现)
- IFormattable,IFormatProvider,ICustomFormatter---C#自定义格式字符串
- 简单的System.IFormattable实现示例:
- 一个实现 IFormattable 接口的例子
- 使用IFormattable接口为自定义类定义格式字符串
- 登山-C#-IFormattable之自定义string的现实格式
- IComparable<>,IFormattable,IEnumerable<>接口使用
- IFormattable and ItemStringFormat in WPF's MVVM
- 自定义View:自定义属性(自定义按钮实现)
- 用Iformattable接口控制.Net中文本格式
- 参与诺基亚N78“连城决” 探索全球最神秘的地区
- 恢复硬盘分区表
- div+css (7)
- 为人
- jquery的几个插件
- 实现自定义IFormattable
- VB基础——还有些运算符
- 利用MailMessage,实现一个简单的mail 发送
- CMP简介
- Linux-2.6.25内核编译简单过程
- Extjs学习
- 美国瑞恩斯大学工商管理硕士博士学位班
- 创造还是研究?——看看你适合当程序员、适合创业吗?
- FreeBSD6.2下编译ACE5.6.4