System.FormatException:索引(从零开始)必须大于或等于零且小于参数列表的大小

时间:2016-03-17 02:16:47

标签: c# formatexception

  

错误:未处理的类型' System.FormatException'发生在mscorlib.dll

     

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

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();
        }
    }
}

1 个答案:

答案 0 :(得分:5)

这一行:

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个项目。