Wednesday, June 8, 2011

Extension Methods In C#


Extension methods are defined as static methods but are called by using instance method syntax. Their first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier. Extension methods are only in scope when you explicitly import the namespace into your source code with a using directive.
The following example shows an extension method defined for the System.String class. Note that it is defined inside a non-nested, non-generic static class:


namespace ExtensionMethods
{
    public static class MyExtensions
    {
        public static int WordCount(this String str)
        {
            return str.Split(new char[] { ' ', '.', '?' }, 
                             StringSplitOptions.RemoveEmptyEntries).Length;
        }
    }   
}
The WordCount extension method can be brought into scope with this using directive:
using ExtensionMethods;
And it can be called from an application by using this syntax:
string s = "Hello Extension Methods";
int i = s.WordCount();
In your code you invoke the extension method with instance method syntax. However, the intermediate language (IL) generated by the compiler translates your code into a call on the static method. Therefore, the principle of encapsulation is not really being violated. In fact, extension methods cannot access private variables in the type they are extending.
For more information, see How to: Implement and Call a Custom Extension Method (C# Programming Guide).

Introduction to inheritance, polymorphism in C#

Very good explanation of Inheritance, Polymorphism with examples.

Introduction to inheritance, polymorphism in C# - CodeProject

Hats off to the writer.

C# Inheritance

A very good tutorial on Inheritance. Very basic and good to know stuff. Thumbs up to the writer.

C# Station: C# Tutorial Lesson 08 - Class Inheritance

Tuesday, June 7, 2011

How To Capture Screen of HTC Android Devices (Screen Shot)

There are two ways to capture your cell's screen:

1)



2) If Above Method Doesn't work read this link. It worked for me.
http://jamesgiang.wordpress.com/2010/04/25/adb-drivers-for-htc-desire/

Things to keep in mind when developing application for Azure Cloud.


Things to keep in mind when developing application for Azure Cloud.

1) All Assesmbly Projects(Dlls) should be built with Platform targer set to "Any CPU", If Still at publish time the doesn't show "Configuration: Release Any CPU" please refer to this : "http://blog.noop.se/archive/2009/06/24/class-libraries-do-not-work-in-windows-azure-using-visual-studio-2010.aspx"

2) For Deployment in Azure Cloud:


   a) Deploying For 1st Time, If No Certificate is Present:
  1. Publish your Cloud Project locally by Right Clicking the cloud project And selecting Publish and select "Create Service Package Only", After successful publish it will create 2 files with following extensions : (cscfg & cspkg). 
  2. Create "New Hosted Service" on Azure. If you face any problem please refer this;      "http://blog.toetapz.com/2010/12/15/how-to-deploying-wcf-service-to-windows-azure/"

*You can deploy Azure Project by Right Clicking the cloud project And selecting Publish and select "Create Service Package Only" everytime and   selecting "Upgrade" this will popup a window and you just have to tell the path of your webservice's packages.

    b) If you want to deploy it directly through Visual Studio:
    Refer to this link: "http://msdn.microsoft.com/en-us/library/ff683672.aspx"