Carlos
Carlos

Reputation: 47

C# question Index was outside the bounds of the array

This is part of a parser that read data from a txt file and insert it on SQL. I am getting the error: System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'


    while (line != null)
    {
        //Console.WriteLine("I am here");
    
        if (line.Contains("TIMESTAMP"))
        {
            //Console.WriteLine("I am TS");
    
            TSitems = line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
            TScount += 1;
        }
        else if (line.Contains("OUT:"))
        {
            //Console.WriteLine("I am CO");
            LicenseCheckout checkoutInfo = new LicenseCheckout();
            COitems = line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
            checkoutInfo.Date = DateTime.ParseExact(TSitems[3], "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture);
            checkoutInfo.TScount = TScount;
            checkoutInfo.checkoutTimeString = COitems[0];
            DateTime time = DateTime.ParseExact(COitems[0], "H:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
            checkoutInfo.CheckoutTime = checkoutInfo.Date.Add(time.TimeOfDay);
            //Console.WriteLine(checkoutInfo.CheckoutTime);
            checkoutInfo.LicenseType = COitems[3].Trim('"');
            checkoutInfo.PcName = COitems[4].Split('@')[1];
            checkoutInfo.UserName = COitems[4].Split('@')[0].ToLower().Trim();
            checkoutInfo.SiteCode = COitems[4].Split('@')[1].Substring(0, 3);
            if (UserNameDict.ContainsKey(checkoutInfo.UserName))
            {
                checkoutInfo.FullUserName = UserNameDict[checkoutInfo.UserName];
            }
            else

Ohh almost forget to say that I am not a developer.

enter image description here

Upvotes: 0

Views: 32

Answers (0)

Related Questions