Sunday 28 July 2013

enum (Enumeration)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace enum_sample
{
    class Program
    {
        public enum MeetingImportance
        { Trivial,Regular,Critical }
        static void Main(string[] args)
        {
            MeetingImportance meet = MeetingImportance.Critical;
            int value = (int)MeetingImportance.Critical;
            if (meet == MeetingImportance.Trivial)
            {
                Console.WriteLine("Trivial:{0}",value);
            }
            else if (meet == MeetingImportance.Regular)
            {
                Console.WriteLine("Regular:{0}",value);
            }
            else if (meet == MeetingImportance.Critical)
            {
                Console.WriteLine("Critical:{0}",value);
            }
        }
    }
}







Downlaod Enum Source Code


Wednesday 3 July 2013

Threading

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace AbortExceptionSample
{
    class Abort_Exception
    {
        public static void ChildThreadcall()
        {
            try
            {
                Console.WriteLine("Child Thread Started");
                Console.WriteLine("Child thread - counting to 10");
                for (int i = 0; i <= 10; i++)
                {
                    Thread.Sleep(2000);
                    Console.WriteLine("{0}...", i);
                }
                Console.WriteLine("Child Thread Finished");
            }
            catch (ThreadAbortException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public static void Main(string[] args)
        {
            ThreadStart childRef = new ThreadStart(ChildThreadcall);
            Thread ChildThread = new Thread(childRef);
            ChildThread.Start();
            Console.WriteLine("Main -   Sleping for 2secs");
            Thread.Sleep(5000);
            Console.WriteLine("\nMain - Aborting Child Thread");
            ChildThread.Abort();
        }
    }
}







Download Thread Source Code