Tuesday, February 10, 2009

why int(xx) != convert.toint(xx)

Lets take code snippet.
    int no = 55;
            object obj = no;
            Int16 shortInt;
            shortInt = Convert.ToInt16(obj);//Hold good
            shortInt = (Int16)obj;//Error

In the above example, we are trying to assign a integer value to a object.
            object obj = no;
As you expect, a boxing happens at that point.

But to our surprise, when we try to unbox the value, we end up in error where as when we use the convert function, it works without issues. 

The concept behind the working is simple.
1) When you box a value with a specific type, you have to unbox the value with the same type. Else you will end up in cast exception error.
2) The convert function first unboxes it with proper type and then casts it to specific type.

Hope it makes it clear.


Tuesday, October 14, 2008

Information on belgium visa- applying from London UK

Last week, I applied for belgium tourist visa. I am an indian national, working in London, UK under HSMP visa. I thought it could be of help to others who are planning to do the same. It will even apply for the people who are planning to apply for schengen visa for their europen trip.

First let me list out few facts.

1) Belgium embassy doesnt entertain visa with multiple entries. And especially, if you are tourist, you got little chance to get a visa with multiple entry .
2) They are very strict in terms of issuing visa. So make sure that the application form is completly filled to avoid any kind of rejection.
3) Belgium embassy receive all our visa applications through a thrid party know as vfs. You can get their details at this link. http://www.vfs-be-uk.com/
4) Since I am from London, I need to apply at VFS office located at central london. If you are applying in the same branch and if you are unaware of streets of central london, make sure that you carry a detailed map. It would be very confusing. One of the landmark i would suggest is Nandos located close to leicester square underground tube station.
5) Inside the application office, they do have a photocopier and provision for taking passport photos. But I would advise to rely on it as a last resort.

Below are the list of documents I submitted. It could be a remainder for all who are planning.

1. My tenancy agreement for my address proof.
2. My bank statements & salary slips as proof for funds.
3. Letter from my employer stating my employment details
4. Annual multi-trip Travel insurance
5. Euro star travel tickets
6. Printout of my hotel accommodation.
7. My valid Indian Passport
8. Photocopy of my credit card.


Good luck.

Friday, August 1, 2008

Interesting Arithmetic Operations

I came across an interesting piece of code snippet. You are invited to take the guess of the result.

try
{
int i = 1;
Console.WriteLine(i + int.MaxValue);
Console.ReadLine();
}
catch (Exception Ex)
{
Console.WriteLine("Crazy operation");
}

You will be surprised to see that the above code snippet gets executed without any exception. Apparently the framework masks any overflow exception that are raised when overflow exceptions happen during addition or subtraction.
Now the question is how to prevent this from happening.

try
{
checked
{
int i = 1;
Console.WriteLine(i + int.MaxValue);
Console.WriteLine(int.MinValue - i);
Console.ReadLine();
}
}
catch (Exception Ex)
{
Console.WriteLine("Crazy operation");

}

Using check operator ensures that exceptions are raised when overflow happens.

Friday, June 27, 2008

A peek into WPF

Just like me, most of us will be wondering what’s so new with WPF.
Why there is a big buzz for it? How come it’s much powerful than the current winforms?
Well. To get it, first we need to understand the technology behind current winforms, especially the windows graphics. Windows application relies on two significant parts of windows operation system.
User32: for look and feel.
GDI/GDI+: For rendering

Over the last decade, windows have come up with various technologies like VB, VC++ and.NET framework. Though this technologies provided developers with new API’s for access windows graphics, these API’s acted as a wrapper on the existing User32 and GDI/GDI+ API’s. Hence, so far, we are using the same technology which was developed decades ago.
In the meanwhile, one can see a huge development in graphics rendering in game arena. If you are a normal user, you will be wondering how Microsoft was able to achieve it. Microsoft over came the limitation of user32 and GDI by means of DirectX. MS closely worked with graphics card vendors to create DirectX whose design mandate was speed.
Well, but why am I talking about DirectX here. So far, DirectX was a game developer’s toolkit. But WPF is going to use DirectX as it rendering engine.
Moreover, WPF is intelligent enough. The rendering work is offloaded on graphic process located in graphic card instead of CPU.
If you are a gamer, you can very well understand the power of DirectX. Now we can harness it for traditional windows application. So I leave it to your imagination what WPF is capable of.