【问题标题】:System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument listSystem.FormatException:索引(从零开始)必须大于或等于零且小于参数列表的大小
【发布时间】:2016-07-03 04:58:22
【问题描述】:

错误:mscorlib.dll 中出现“System.FormatException”类型的未处理异常

附加信息:索引(从零开始)必须大于或等于零且小于参数列表的大小。

namespace Inheritance
{
    abstract class Airlines
    {
        public int Aid;
        protected string Aname, DOD, ToAdd, ToFrom, FromAdd;
        protected float Cost;
        public void Accept()
        {
            Console.WriteLine("Enter the Aid,Aname");
            Aid = Convert.ToInt32(Console.ReadLine());
            Aname = Console.ReadLine();
            Console.WriteLine("Enter DOD,ToAdd,FromAdd");
            DOD = Console.ReadLine();
            ToAdd = Console.ReadLine();
            FromAdd = Console.ReadLine();
            Console.WriteLine("Enter the  Cost");
            Cost = Convert.ToSingle(Console.ReadLine());
        }

        public abstract void DisplayInfo();
        public abstract void facility();
    }
    abstract class SpiceJet : Airlines
    {
        string PaymentMode;
        public void AcceptData()
        {
            //Console.WriteLine("Welcome");
            Accept();
        }

        public void payment()
        {
            Console.WriteLine("Enter The Payment Mode =");
            PaymentMode = Console.ReadLine();

        }
        public override void DisplayInfo()
        {
            Console.WriteLine("Aid id :{0},Aname is:{1},DOD is :{2},ToAdd is:{3},FromAdd is :{4},Cost is :{5},PaymentMode is :{6}", Aid, Aname, ToAdd, FromAdd, Cost, PaymentMode);

        }
        public abstract void typeclass();

    }
    class SpiceJetchild : SpiceJet
    {
        public override void facility()
        {

        }
        public override void typeclass()
        {

        }
    }
    class Program
    {
        static void Main(string[] args)
        {

            //Airlines a = new Airline();
            //SpiceJet sj = new SpiceJet();
            SpiceJetchild sj = new SpiceJetchild();
            sj.AcceptData();
            sj.payment();
            sj.DisplayInfo();
            sj.facility();
            sj.typeclass();
            Console.ReadKey();
        }
    }
}

【问题讨论】:

    标签: c# formatexception


    【解决方案1】:

    这一行:

    Console.WriteLine("Aid id :{0},Aname is:{1},DOD is :{2},ToAdd is:{3},FromAdd is :{4},Cost is :{5},PaymentMode is :{6}", Aid, Aname, ToAdd, FromAdd, Cost, PaymentMode);
    

    您指定了 7 个项目,但您只提供了 6 个。

    【讨论】:

    猜你喜欢
    • 2011-04-18
    • 2011-12-19
    • 2023-04-11
    • 2016-04-01
    • 2018-07-26
    • 2011-11-20
    • 1970-01-01
    • 2013-05-27
    相关资源
    最近更新 更多