C# beginner

yibman's Avatar, Join Date: May 2006
Newbie Member
Hi i am a beginner in c# programming. Can Anybody tell me what happens in the code lines for this class :
Code: C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;

namespace WindowsApplication3.Data
{
    public class LogEntryCollection : ObjectCollection<LogEntry>
    {
        private DataObject owner;
        public DataObject Owner
        {
            get { return this.owner; }
        }

        protected override void InsertItem(int index, LogEntry item)
        {
            LogEntry le = new LogEntry(this.owner);
            le.Text = item.Text;
            le.Time = item.Time;
            item = le;

            base.InsertItem(index, item);
        }

        public void Persist()
        {
            DataManager.Current.Engine.PersistChanges(this);
        }

        public LogEntryCollection(DataObject owner)
        {
            this.owner = owner;
        }

        public LogEntry[] Sort()
        {
            LogEntry[] coll = new LogEntry[this.Count];
            this.CopyTo(coll, 0);

            for (int i = 0; i < coll.Length - 1; i++)
            {
                for (int j = 0; j < coll.Length - 1 - i; j++)
                {
                    if (coll[j + 1].Time.CompareTo(coll[j].Time) > 0)
                    {
                        Swap(ref coll[j], ref coll[j + 1]);
                    }
                }
            }

            return coll;
        }

        private static void Swap(ref LogEntry le1, ref LogEntry le2)
        {
            LogEntry tmp = le2;
            le2 = le1;
            le1 = tmp;
        }
    }
}

Last edited by shabbir; 7May2006 at 05:39.. Reason: Code formating.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
It logs the necessary data through the LogEntry class.