[OP忽略答案] iformattable接口实现 [英] [OP ignores answers] iformattable interface implementation

查看:77
本文介绍了[OP忽略答案] iformattable接口实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生!

我编写了一个使用 IFormattable 界面来格式化数据的代码。

但是这是错误的....

错误代码如下:



代码:

sir!
I've written a code that use IFormattable interface to format the data.
but it is giving error....
faulty code is below:

code:

using System;
using System.Collections.Generic;
using System.Text;

namespace Iformattable_demo
{
    class prices : IFormattable   //error is in this line
    {
        double Price;
        public prices(double _price)
        {
            Console.WriteLine("Welcome to Iformattable interface demonstration");
            this.Price = _price;
        }

        public string toString(string format, IFormatProvider fp)
        {
            if (format == "$")
            {
                return "$" + this.Price.ToString("0.00");
            }
            else
            {
                if (format == null || format.Trim().Equals(""))
                {
                    return this.Price.ToString();
                }
                else
                {
                    return format + " " + this.Price.ToString();
                }
            }
        }

        public static void Main(String[] at)
        {
            prices pri = new prices(14.98);
            Console.WriteLine("{0:$}", pri);
            Console.WriteLine(pri);
            Console.ReadLine();
        }

        //  #region IFormattable Members


        //#region IFormattable Members

        //public string ToString(string format, IFormatProvider formatProvider)
        //{
        //    throw new NotImplementedException();
        //}

        //#endregion
    }
} 



错误是:


the error is:

"Error	1	'Iformattable_demo.prices' does not implement interface member 'System.IFormattable.ToString(string, System.IFormatProvider)'	c:\users\tushar\documents\visual studio 2010\Projects\Iformattable_demo\Iformattable_demo\Prices.cs	7	11	Iformattable_demo."



请帮助我先生。


Please help me sir.

推荐答案


{
return
") { return "


+ this .Price.ToString( 0.00);
}
else
{
if (格式== null || format.Trim()。Equals( ))
{
返回 。价格的ToString();
}
其他
{
返回格式+ + this .Price.ToString ();
}
}
}

public static void Main( String [] at)
{
price pri = 价格( 14 98 ) ;
Console.WriteLine( {0:
" + this.Price.ToString("0.00"); } else { if (format == null || format.Trim().Equals("")) { return this.Price.ToString(); } else { return format + " " + this.Price.ToString(); } } } public static void Main(String[] at) { prices pri = new prices(14.98); Console.WriteLine("{0:


},pri);
Console.WriteLine(pri);
Console.ReadLine();
}

// #region IFormattable会员


// #region IFormattable会员

// public string ToString(string format,IFormatProvider formatProvider)
// {
// 抛出新的NotImplementedException();
// }

// #endregion
}
}
}", pri); Console.WriteLine(pri); Console.ReadLine(); } // #region IFormattable Members //#region IFormattable Members //public string ToString(string format, IFormatProvider formatProvider) //{ // throw new NotImplementedException(); //} //#endregion } }



错误是:


the error is:

"Error	1	'Iformattable_demo.prices' does not implement interface member 'System.IFormattable.ToString(string, System.IFormatProvider)'	c:\users\tushar\documents\visual studio 2010\Projects\Iformattable_demo\Iformattable_demo\Prices.cs	7	11	Iformattable_demo."



请帮助我先生。


Please help me sir.


这篇关于[OP忽略答案] iformattable接口实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆