Friday 24 August 2012

Get And Set Property

Definition:
         public class MyClass
{
    private int _age;

    public int Age
    {
          get{ return _age;  }
          set{ _age = value; }
    }
}
Uses:

  • You need to more than just a simple get/set - in this case, you should just avoid using automatic properties for this member.
  • You want to avoid the performace hit of going through the get or set and just use the member directly - in this case, I'd be suprised if there really was a performace hit. The simple get/set members are very very easy to inline, and in my (admitly limited) testing I haven't found a difference to using the automatic properties vs accessing the member directly.
  • You only want to have public read access (i.e. just a 'get') and the class write to the member diectly - in this case, you can use a private set in your automatic property. i.e.
    public class MyClass
    {
        public int Age {get; private set;} }
This usually covers most the reasons for wanting to directly get to the backing field used by the automatic properties.
Example Program :

using System;

class Example
{
    int number;
    public int Number
    {
 get
 {
     return number;
 }
 set
 {
     number = value;
 }
    }
}

class Program
{
    static void Main()
    {
 Example example = new Example();
 example.Number = 5; // set { }
 Console.WriteLine(example.Number); // get { }
    }
}
OutPut:
       5

Sunday 12 August 2012

Microsoft TechEd 2012 on the Go.. Are you attending?

Well,  Microsoft is going Big with their event TechEd 2012 which will be held just in 2 days.Everyone is excited to visit Bangaluru for this awesome event and learn lot of technology

Visit the link below to know more about the event
Microsoft TechEd India 2012 -> Go Big

Working with NotificationUI on browsers with HTML5


Notification is one of the interesting thing that browsers are adding support to. Generally when we think of Web notification we always go for some HTML popup or using a new window through Javascript. But those html are generally does not follow any standards or even looks different to the user to different sites. Hence few of the notifications lacks consistency. HTML5 introduces new notification specs which enable the browser to send its own notification rather than going with custom notifications from the developer.
The notifications is now currently implemented in Chrome, but it will be implemented in latest releases of other browsers too. Let us look how to use notification  in your browser.
To request for notification use the following code :
window.webkitNotifications.requestPermission();
When the browser asks for notification, it will popup one message to the user to allow or deny. If the user allows the notification, the notification service gets enabled and the site can send notification to the browser.
if (window.webkitNotifications.checkPermission() == 0) {
var notification = window.webkitNotifications.createNotification(imgpath, 'Notification received', 'Hii, this is special notification');
notification.show();
}
So when we use createNotification it will create a notification object with the image , title and the message which needs to be notified. The show() method will show the notification to the user.

Memory Mapping file inside .NET Framework

.NET introduces a separate namespace to handle Memory Mapping files. Previously, we needed to do this using unmanaged Api's but with the introduction of managed API into the .NET framework library, it becomes very easy to handle MemoryMapping file directly from .NET library.

As memory mapping files are loaded into memory on a separate range of address space, two process can easily share the same page file instance and thus interprocess communication can be made with fast access to memory. It is recommended to back data with an actual disk file when large data is loaded into memory, so that there is no memory leak on the system when there is large memory pressure.

Friday 10 August 2012

C# Code for Floyds Triangle


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

namespace Floyd
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, i, j;
            string s;
            Console.WriteLine("Enter The Row Value..");
            n = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter The String..");
            s = Console.ReadLine();
            for (i = 0; i <= n; i++)
            {
                for (j = 0; j <i; j++)
                {
                    Console.Write("  " +s[j]);
                   
                 }
                Console.WriteLine("  ");
            }
                Console.ReadLine();
        }
    }
}