Thursday, 15 October 2015

Does finally block is always executed ?

If there is try-catch-finally or try-finally block then finally block is always executed?
But this is not the case every time. There are scenarios when even finally block dos not execute. What are those scenarios?

There are few scenarios when even finally
block does not get executed. Finally block does not execute when the
following type of exception occurs

•ExecutionEngineException

•StackOverflowException

ExecutionEngineException occurs when there is some error in Common
Language Runtime. A case could be if there is some exception while
executing garbage collection. This exception also occurs if
Environment.FailFast() fired.

StackOverflowException occurs when there is no space available in stack to execute further.

Wednesday, 14 October 2015

How can you recognize whether a service is a Web API?

In .Net you can check the URL if contains asmx (web service) .Svc (WCF service) but this approach will definitely fail if service is developed in any other technology like java, Oracle. or even in .net by using http handler we can make it in a way where we can use a different extension. Below is the snapshot depicting the difference between websservice(asmx) and web api literally there is nothing in response which tells you whether it is a web service or web api.

Sunday, 11 October 2015

MVC : How to catch All Invalid routes/url

How to catch All url (if i want to disallow all urls other than my home page ) To catch all url other than specified Add this line in end of RegisterRoutes() Method .

Why the output is 42 ?

Try this Out Guys --
int a = 20;
a++; //21
a += a--; //21+21 what about --?
Console.WriteLine(a);
why the output is 42? why not 41 ?
Answer :-
Check my thread
http://forums.asp.net/t/1957883.aspx
Or check below
This is because these are postfix operations, so they are going to output the value of the variable prior to your increment or decrement statements.
As per the MSDN documentation :
The ++ and -- operators also support postfix notation, (Section 7.5.9). The result of x++ or x-- is the value of x before the operation, whereas the result of ++x or --x is the value of x after the operation. In either case, x itself has the same value after the operation.
You can see a working example demonstrating this below :
//Declare your integer value
int a = 20;
//Increment it
Console.WriteLine(a++);
//Now you'll see that your value is 21
Console.WriteLine(a);
//The following line is going to output (21) + (21)
Console.WriteLine(a += a--);
Example
If you really wanted to output 41, you would need to use postfix notation instead which would output the value after your increment or decrement operation occurred by changing this line :
a += a--;
to this :
a += --a;

Regex Which Allows Unicode -(Greek And Latin Words )

I had a requirement to allow Greek And Latin Words in email. so what I did? I changed the Regex

Excluding " (Double Quotes) Now it supports Greek and latin word too, voila  :)