Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   C# beginner (http://www.go4expert.com/forums/c-sharp-beginner-t786/)

yibman 7May2006 00:12

C# beginner
 
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;
        }
    }
}


shabbir 7May2006 14:33

Re: C# beginner
 
It logs the necessary data through the LogEntry class.


All times are GMT +5.5. The time now is 23:16.