Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C# 4.0

How does it work in C#? - Part 1

Rate me:
Please Sign up or sign in to vote.
4.79/5 (78 votes)
20 Nov 2012CPOL7 min read 207.8K   2.5K   246  
How does var, auto implemented properties and += or -= of events work in C# programming language.
namespace TestHarness
{
    using System;
    using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            AutoImplementatedPropertiesTest();
            EventDelegateTest();
        }

        private static void EventDelegateTest()
        {
            Console.WriteLine("\n2)Event and Delegate += Test:");
            AddRemoveHandlerOfEvent addRemoveHandlerOfEvent = new AddRemoveHandlerOfEvent();
            LogIt logItObject = addRemoveHandlerOfEvent.InitialiseLogIt();
            addRemoveHandlerOfEvent.GetInitialMethodPointer().ToList().ForEach(item => Console.WriteLine(item));
            addRemoveHandlerOfEvent.GetInvocationListFrom(logItObject).ToList().ForEach(item => Console.WriteLine(item));
        }

        private static void AutoImplementatedPropertiesTest()
        {
            Console.WriteLine("1) AutoImplementatedProperties Test:");
            AutoImplementatedProperties autoImplementatedProperties = new AutoImplementatedProperties();
            Person person = autoImplementatedProperties.CreateATestObject();
            Console.WriteLine("[] Explore all the members...\n");
            autoImplementatedProperties.ExploreMembers(person).ToList<string>().ForEach(item => Console.WriteLine(item));
            Console.WriteLine("[] Explore all the private fields...\n");
            autoImplementatedProperties.ExplorePrivateFields(person).ToList<string>().ForEach(item => Console.WriteLine(item));
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Australia Australia

Comments and Discussions