Language Enhancements In C# 3.0 and VB 9

There are so many new features added as Language Enhancement for C# 3.0 and VB 9.0 in Visual Studio 2008 (along with .NET Framework 3.5). Here, I’m compiling a quick list of important ones and will share some resources from where you can learn more about the same.

  1. Local Type Inference
    Visual Studio uses type inference to determine the data types of local variables declared without data-type. The compiler infers the type of the variable from the type of the initialization expression. This enables you to declare variables without explicitly stating a type, as shown in the following example.
    String str1 = "Mayur Tendulkar";
    var str2 = "Mayur Tendulkar";

    For more information visit following links:
    http://msdn2.microsoft.com/en-us/library/bb384937.aspx

  2. Object and Collection Initializers
    Object and Collection Initializers let you assign values to any accessible fields or properties of an object at creation time without having to explicitly invoke a constructor
    class Person
    {
    String Name { get; set; }
    String EMailID { get; set; }
    }
    class PersonImplementation
    {
    static void CreatePerson()
    {
    //Object Initializer Used
    Person p = new Person { Name = "Mayur Tendulkar", EMailID = "mayur.tendulkar@gmail.com" };
    //Collection Initializer (with Object Initializer) Used
    List per = new List
    {
    new Person() { Name = "ABC", EMailID = "abc@abc.com"},
    new Person() { Name = "XYZ", EMailID = "xyz@xyz.com"}
    };
    }
    }

    For more information, visit following link:
    http://msdn2.microsoft.com/en-us/library/bb384062.aspx

  3. Anonymous Types
    Anonymous types enable you to create objects without writing a class definition for the data type. Instead, the compiler generates a class for you. The class has no usable name, inherits directly from Object, and contains the properties you specify in declaring the object. Because the name of the data type is not specified, it is referred to as an anonymous type.
    var Student = new { Name = "Mayur", LastName = "Tendulkar"};

    For more information, visit following link:
    http://msdn2.microsoft.com/en-us/library/bb397696.aspx

  4. Auto Implemented Properties
    Auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field can only be accessed through the property’s get and set accessors.
    class Female
    {
    string Name { get; set; }
    int Age { private get; set; } //Write only
    int Mobile { get; private set; } //Read only
    }

    For more information visit following link:
    http://msdn2.microsoft.com/en-us/library/bb384054.aspx

  5. Partial Method
    Partial methods enable the implementer of one part of a class to define a method, similar to an event. The implementer of the other part of the class can decide whether to implement the method or not. If the method is not implemented, then the compiler removes the method signature and all calls to the method. Therefore, any code in the partial class can freely use a partial method, even if the implementation is not supplied. No compile-time or run-time errors will result if the method is called but not implemented.
    // Definition in file1.cs
    partial void onNameChanged();

    // Implementation in file2.cs
    partial void onNameChanged()
    {
    // method body
    }

    For more information visit following link:
    http://msdn2.microsoft.com/en-us/library/wa80x488.aspx

In this blog post we seen 5 new concepts that are included in VS2008 (.NET 3.5) and in next post, we’ll see some more of them.

WiMo Development Overview

In this video, I’ll be showing you, how developers can build simple applications for Microsoft Windows Mobile platform. This is a basic introductory video, but in coming videos, I’ll add more stuff depending on your feedback.

http://images.video.msn.com/flash/soapbox1_1.swf 
Happy Coding :)

State and Notifications with Windows Mobile

In last post, we got to know about .NET framework using a real-life example of Hotel Industry. There are so many technologies that help us to make our life much easier and hence we can take real life examples to understand them – inside out. I love to explain some of them as I encounter few of them in my day-to-day life – as a hobbyist programmer, as a student, as an intern and as an individual. So, it will help you to understand those “geeky” worlds easily, even if you are novice.
Here, in this blog roll, I’m going to talk about THE BEST feature that is available in Windows Mobile platform – State and Notification APIs OR you may heed it as SNAPI when you will be surrounded by geeks.
Let’s take an example over here. Let’s suppose you are hungry, and then you may open the refrigerator to check, if anything is there to eat. This is like you are checking the STATE of your refrigerator.
But sometimes, even if you’re not hungry and if your mom is leaving for her job, he may tell you, that, there is ice-cream in the fridge, if you want, take it. In this case, she is NOTIFYING you about it.
There are many such events happen on your Windows Mobile that you may want to know, when those happened, what is the status of your device then, like that. SNAPI helps you to monitor such things.
Let’s take a simple example of Incoming Call. Suppose, you want to receive a Message from your device, whenever there will be an Incoming Call. Ok. When there will be an incoming call, you’ll get notified by ringtone or by vibrations. But, here, just to understand the technology, let’s take this example.
So, there are few steps that you need to follow, when building SNAPI based application.
Here, I’m writing a code, which will give you the idea about how you can build such kind of application.

Imports Microsoft.WindowsMobile
'This namespace is required to run Windows Mobile application.
Imports Microsoft.WindowsMobile.Status
'This namespace is required to use SNAPI classes and functions.
Public Class frmMain
Dim state As SystemState = New SystemState(SystemProperty.PhoneIncomingCall)
'First Create object of SystemState and provide PhoneIncomingCall property as a parameter
'Then create a method, which will be called for evey notification OR state change
Private Sub IncomingCallAlert()
'This method is supposed to be called everytime, when there will be new Incoming Call
If MessageBox.Show("Incoming Call...") = Windows.Forms.DialogResult.OK Then
'If there is an Incoming Call, then just show a Message Box with Alert
Me.Hide()
'After showing, hide the form.
End If
End Sub
'Now launch the State and Notification service, whener application is launched.
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Start the notification process, when main form is loaded
AddHandler state.Changed, AddressOf IncomingCallAlert
'Add event handler, so whenever, there will be incoming call,
'IncomingCallAlert() method will be called.
End Sub
End Class

You can find more information about SNAPI on following links.
Besides the example, you can do much more things with SNAPI. To know more about SNAPI on MSDN,
click here
You can get more information about SNAPI properties like PhoneIncomingCall and others, for this
click here.
There is a webcast on building SNAPI enabled Windows Mobile Applications on MSDN Events. To view this webcast
click here.
There is a very nice article written by Don Sorcinelli, to read,
click here.
I hope, this will give you a clear idea about SNAPI and help you to build nice applications for Windows Mobile.
Happy Coding J