System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list

avnish pandey picture avnish pandey · Mar 17, 2016 · Viewed 11.2k times · Source

Error : An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

Additional info : Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

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

Answer

Otávio Décio picture Otávio Décio · Mar 17, 2016

This line:

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

you specify 7 items but you are providing only 6.